制作一个Im应用,在与对方交流时不发送对方的消息通知,离开与对方交流的activity时发送消息通知。请教各位大神这个要怎么实现
迷茫2017-04-17 17:54:50
When there are new chat messages, the server will push them uniformly. The client determines that if it is currently chatting with this person, it will be displayed in the dialog box, otherwise a notification will be generated and displayed in the notification area.
ringa_lee2017-04-17 17:54:50
Personal understanding:
You can use a Service to uniformly manage Socket message reception, and determine the push position of the message based on the current page status. If the message is pushed to the chat page, otherwise it will be notified to the notification bar
大家讲道理2017-04-17 17:54:50
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(NEW_MESSAGE_NOTIFICATION_ID);
This NEW_MESSAGE_NOTIFICATION_ID is added when sending notification
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(NEW_MESSAGE_NOTIFICATION_ID, builder.build());
伊谢尔伦2017-04-17 17:54:50
This should be your question about the overall design of the software. I used to make an Android IM software. The implementation is very simple. It is to maintain a CurrentChatUser in the Application and store the user ID corresponding to the current chat interface. Then when you enter this Activity (if your chat interface is Activity, Fragment is the same), save the user ID of the person you are currently chatting to in Application in onResume, and delete it in onDestroy when you leave. so that when you receive a new message, you can judge whether the message you received is from this person, and then decide whether to notify you. If so, you will not be notified. It will be displayed directly on the chat interface. If not, the user will be notified of the new message. information.
ringa_lee2017-04-17 17:54:50
If you are on the chat page, stop the service and send it to the chat page