Уведомление не отображается в Android 9 - PullRequest
0 голосов
/ 16 октября 2018

Я использую этот код для отображения уведомлений в моем приложении для Android.Это работает нормально во всех версиях Android, но в Android 9 не отображается никаких уведомлений.

Я пытался реализовать это другим способом, но ничего не получалось.

    public void showNotification(String heading, String description, String imageUrl, Intent intent){
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    createChannel();
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this,"channelID")
            .setSmallIcon(R.drawable.logo)
            .setContentTitle(heading)
            .setContentText(description)
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    int notificationId = (int) ((new Date().getTime() / 1000L) % Integer.MAX_VALUE);
    notificationManager.notify(notificationId, notificationBuilder.build());
}

public void createChannel(){
    if (Build.VERSION.SDK_INT < 26) {
        return;
    }
    NotificationManager notificationManager =
            (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationChannel channel = new NotificationChannel("channelID","name", NotificationManager.IMPORTANCE_DEFAULT);
    channel.setDescription("Description");
    notificationManager.createNotificationChannel(channel);
}

Спасибо ..

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