应用程序不可用时的Android通知';背景中的t
我在安卓系统中遇到了一个奇怪的通知问题。我以这种方式创建通知:应用程序不可用时的Android通知';背景中的t,android,android-intent,push-notification,Android,Android Intent,Push Notification,我在安卓系统中遇到了一个奇怪的通知问题。我以这种方式创建通知: NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Intent notificationIntent = new Intent(context, MyClass.class); notificati
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(context, MyClass.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
notificationIntent.putExtra("data", value);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Notification updateComplete = new NotificationCompat.Builder(context)
.setContentTitle(title)
.setContentText(msg)
.setTicker(title)
.setWhen(System.currentTimeMillis())
.setContentIntent(contentIntent)
.setDefaults(Notification.DEFAULT_SOUND)
.setAutoCancel(true)
.setSmallIcon(R.drawable.icon_notifications)
.build();
notificationManager.notify(100, updateComplete);
当应用程序运行时(或在后台),用户点击通知,一切正常onNewIntent
被调用,数据在附加中。但当应用程序未运行或未在后台运行时,则不会调用onNewIntent()
。我尝试使用getIntent()
从onCreate()
获取intent
,但它从来没有额外的功能。当应用程序尚未运行时,是否仍有额外的功能
我的所有活动都是
singleTop
尝试设置一些操作:
notificationIntent.setAction(Long.toString(System.currentTimeMillis()));
然后在onCreate中获得额外功能
您也可以尝试将pendingent.FLAG\u UPDATE\u CURRENT
替换为0