应用在Android 8及更高版本中未显示通知

时间:2020-10-01 13:59:48

标签: android android-studio notifications android-notifications notification-channel

该通知在Android 7中工作正常,但是当我尝试在Android 8和Android 10上运行该应用程序时 它不再工作了 我尝试创建一个新的通知频道,但仍然相同 有任何想法吗?

Chronometer.java

  private void createNotificationChannel() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        CharSequence name = getString(R.string.channel_name);
        String description = getString(R.string.channel_des);
        String id = getString(R.string.channel_id2);
        int importance = NotificationManager.IMPORTANCE_LOW;
        int notifyID = 1;
        Intent intent = new Intent(this, chronometer.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
                .setContentTitle("Rastreador de uso")
                .setContentText("Acesso rápido ao app")
                .setChannelId(id)
                .setContentIntent(pendingIntent)
                .setAutoCancel(false);
        NotificationManager notificationManager = getSystemService(NotificationManager.class);
        NotificationChannel channell = null;
        notificationManager.createNotificationChannel(channell);
        notificationManager.notify(notifyID, builder.build());
    }
}

0 个答案:

没有答案