Smooch对话活动,我如何知道活动何时启动?
问题描述:
我已经实施了smooch。 https://smooch.io/ 而我的问题是,当我从smooch得到通知。如果我在后台,我会在“我的主页”按钮上设置一个“未读消息”,用于我的主要活动。 问题是,当我按通知时,ConversationActivity从那里开始。我需要将未读消息设置为0,因为ConversationActivity已打开。我怎么知道这是什么时候发生的?Smooch对话活动,我如何知道活动何时启动?
我无法修改smooch库中的ConversationActivity.class。 我想过做通知自己,改变接吻创建一个与这一个使用此代码:
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);
}
但我需要在按下通知未读设置为0,而不是当我创建通知。而且我无法将它置于等待意图中
答
您有几个选择。
-
使用onSmoochShown委托回调。
此回调将在会话显示时触发,因此您可以更新未读的计数。使用onUnreadCountChanged委托回调。
只要当前用户的未读计数发生变化,就会调用此代理。您可以使用此回调来相应地更新您的多头。
既然你需要时,通知被窃听是听这些委托回调,这可能是最好的设置您的代理在应用程序的onCreate
,初始化后接吻。
是的,这是有效的。实施代表使之成为可能 –