Пользовательское уведомление не работает в Android Oreo - PullRequest
0 голосов
/ 17 октября 2018

Я пытаюсь создать Уведомление на устройстве Oreo.Я добавил канал и все, но все еще не работает.Я использую Samsung Galaxy J7 для тестирования и вызываю эту функцию в onCreate() своей активности.

  private void sendNotification() {
    Intent intent = new Intent(this, DailyReportActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);

    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    Notification.Builder builder;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        String id = "w01", name = "Some Name";
        int importance = NotificationManager.IMPORTANCE_DEFAULT;
        String desc = "Description";

        NotificationChannel channel = new NotificationChannel(id, name, importance);
        channel.setDescription(desc);
        notificationManager.createNotificationChannel(channel);
        builder = new Notification.Builder(this, id);
    } else
        builder = new Notification.Builder(this);

    builder.setAutoCancel(false);
    builder.setContentTitle("Notification Title");
    builder.setContentText("Content Text");
    builder.setStyle(new Notification.BigTextStyle().bigText("Some Data"));
    builder.setSmallIcon(R.drawable.app_icon);
    builder.setContentIntent(pendingIntent);
    Notification notification = builder.build();

    notificationManager.notify(8, notification);
}

Я не знаю, чего мне здесь не хватает, и она работает на моем устройстве Marshmallow.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...