【问题标题】:Clicking on Notification is not starting intended activity only in AndroidOS Oreo?单击通知不会仅在 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());
}

【问题讨论】:

    标签: android android-intent android-notifications


    【解决方案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);`
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-21
      • 1970-01-01
      • 2020-11-19
      相关资源
      最近更新 更多