我真的认真地尝试了每一种方法和每一个片段,但我仍然无法在中国品牌设备上显示提醒通知。
所以昨天我想为什么不再试一次,但毕竟我仍然无法显示提示通知,直到我手动将应用程序转到设置并授予应用程序的浮动权限。
现在你们中的大多数人可能会说为什么不在用户第一次打开应用程序时将其导航到设置但没有人喜欢即使有其他应用程序(我不是在谈论像 WhatsApp 这样的白名单应用程序)也有 10K 的下载量能够显示抬头通知
这是我的代码,顺便说一句,我尝试设置声音、振动和灯光,但仍然没有显示抬头,是的,每次构建后我都会卸载我的应用程序
public void showNotification(View v){
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
NotificationChannel nc = new NotificationChannel("n","pop up notification", NotificationManager.IMPORTANCE_HIGH);
nc.enableLights(true);
nc.setLightColor(Color.BLUE);
nc.enableVibration(true);
nc.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
NotificationManager nm = getSystemService(NotificationManager.class);
nm.createNotificationChannel(nc);
}
Notification.Builder notification = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
notification = new Notification.Builder(this,"n")
.setContentTitle("Pop up notification")
.setSmallIcon(R.drawable.ic_launcher_background);
}else{
notification = new Notification.Builder(this)
.setContentTitle("Pop up notification")
// .setPriority(Notification.PRIORITY_MAX)
.setSmallIcon(R.drawable.ic_launcher_background);
}
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(1,notification.build());
}