J'ai implémenté smooch. https://smooch.io/ Et mon problème est que lorsque je reçois la notification de smooch. Si je suis en arrière-plan, j'ai mis un "messages non lus" longtemps que j'utilise dans mon activité principale sur le bouton smooch. Le problème est que lorsque j'appuie sur la notification, et le ConversationActivity est démarré à partir de là. J'ai besoin de mettre les messages non lus à 0, parce que le ConversationActivity est ouvert. Comment puis-je savoir quand cela arrive?Smooch ConversationActivity, comment puis-je savoir quand l'activité a été lancée?
Je ne peux pas modifier ConversationActivity.class à partir de la bibliothèque smooch. Je pensais à faire la notification moi-même, et en changeant le bécoter créé un avec celui-ci en utilisant ce code:
private static void generateNotificationSmooch(final Context context, String title, String message) {
if (title == null)
title = context.getString(R.string.passenger_name);
Intent notificationIntent = new Intent(context, ConversationActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
int iUniqueId = (int) (System.currentTimeMillis() & 0xfffffff);
PendingIntent intent = PendingIntent.getActivity(context, iUniqueId, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
mBuilder.setContentTitle(title).setContentText(message).setSmallIcon(R.drawable.notification_icon);
mBuilder.setContentIntent(intent);
Notification notification = mBuilder.build();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notification);
}
Mais je dois régler le non lu à 0 lorsque la notification est pressée, et non lorsque je crée la notification. Et je ne peux pas le mettre dans l'intention en attente
Oui cela fonctionne. la mise en œuvre du Délégué a rendu possible –