来自通知点击的用户
Posted
技术标签:
【中文标题】来自通知点击的用户【英文标题】:User coming from a notification click 【发布时间】:2018-11-25 15:01:41 【问题描述】:如果用户来自通知点击,我想触发 Toast。
但我不知道如何知道用户是否来自通知点击。 知道我是这样设置通知的:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
int importance = NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel channel =
new NotificationChannel(notification_channel, notification_channel, importance);
String description = "A channel which shows notifications about the app";
channel.setDescription(description);
channel.setLightColor(Color.MAGENTA);
NotificationManager notificationManager = (NotificationManager) getApplicationContext().
getSystemService(Context.NOTIFICATION_SERVICE);
if (notificationManager != null)
notificationManager.createNotificationChannel(channel);
String notificationTitle = "Title";
String notificationText = "Notification Text";
Intent intent_not = new Intent(getApplicationContext(), Home_Base.class);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 1, intent_not, FLAG_UPDATE_CURRENT);
//build the notification
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(getApplicationContext(), notification_channel)
.setSmallIcon(R.drawable.fiamma)
.setContentTitle(notificationTitle)
.setContentText(notificationText)
.setAutoCancel(true)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setContentIntent(pendingIntent);
//trigger the notification
NotificationManagerCompat notificationManager =
NotificationManagerCompat.from(getApplicationContext());
notificationManager.notify(123, notificationBuilder.build());
【问题讨论】:
【参考方案1】:尝试使用 intent_not.setAction() 设置操作(例如 On_NOTIFICATION_CLICK)
在 Home_Base 中使用 getIntent().getAction(),尝试从接收到的意图中获取操作。
如果 Home_Base 中收到的操作是 On_NOTIFICATION_CLICK,则它是一个通知点击操作。
【讨论】:
以上是关于来自通知点击的用户的主要内容,如果未能解决你的问题,请参考以下文章