如何解决应用在Android 8及更高版本中未显示通知
该通知在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,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());
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。