Нажатие на Уведомление не запускает намеченную деятельность только в AndroidOS Oreo? - PullRequest
0 голосов
/ 29 июня 2019

Ошибка при нажатии на уведомление на моем устройстве, которое не перенаправлено на активность моего приложения.

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 Ответ

0 голосов
/ 01 июля 2019

Попробуйте использовать этот код, который пришел отсюда 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);`
...