单击通知不会仅在 AndroidOS Oreo 中启动预期活动?
Posted
技术标签:
【中文标题】单击通知不会仅在 AndroidOS Oreo 中启动预期活动?【英文标题】:Clicking on Notification is not starting intended activity only in AndroidOS Oreo? 【发布时间】:2019-11-11 00:40:57 【问题描述】:在我的设备中单击未重定向到我的应用程序活动的通知时出现错误。
private void processStartNotification()
Builder builder = new Builder(this);
builder.setContentTitle("DAILY NOTFICATION!")
.setAutoCancel(true).setColor(getResources()
.getColor(R.color.colorPrimary))
.setContentText("CLICK DAILY NOTIFICATION.")
.setSmallIcon(R.mipmap.appicon1)
.setVibrate(new long[]
1000, 1000, 1000, 1000, 1000
);
builder.setContentIntent(PendingIntent.getActivity(this, NOTIFICATION_ID, new Intent(this, Simplfylast.class), PendingIntent.FLAG_UPDATE_CURRENT));
// The stack builder object will contain an artificial back stack for the started Activity.
// This ensures that navigating backward from the Activity leads out of your application to the Home screen.
builder.setDeleteIntent(NotificationEventReceiver.getDeleteIntent(this));
((NotificationManager) getSystemService("notification")).notify(NOTIFICATION_ID, builder.build());
【问题讨论】:
【参考方案1】:尝试使用来自这里的代码https://developer.android.com/training/notify-user/build-notification#java
// Create an explicit intent for an Activity in your app
Intent intent = new Intent(this, AlertDetails.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("My notification")
.setContentText("Hello World!")
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
// Set the intent that will fire when the user taps the notification
.setContentIntent(pendingIntent)
.setAutoCancel(true);`
【讨论】:
以上是关于单击通知不会仅在 AndroidOS Oreo 中启动预期活动?的主要内容,如果未能解决你的问题,请参考以下文章
Xamarin - Oreo (API 26) Firebase Cloud Messaging 背景通知未显示在通知抽屉中