我使用以下代码来显示我的通知:
NotificationCompat.Builder builder =
new NotificationCompat.Builder(context,
context.getString(R.string.notification_general_id))
.setSmallIcon(R.drawable.iit)
.setContentTitle("something")
.setContentText(notification)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setDefaults(Notification.DEFAULT_ALL)
.setAutoCancel(true);
// https://stackoverflow.com/a/28251192/2287994
long time = new Date().getTime();
String tmpStr = String.valueOf(time);
String last4Str = tmpStr.substring(tmpStr.length() - 5);
int notificationId = Integer.parseInt(last4Str);
Log.d(TAG, "notificationId " + notificationId);
notificationManager.notify(notificationId, builder.build());我使用以下代码创建通知通道:
// for showing general notifications
NotificationChannel generalNotificationsChannel = new NotificationChannel(
getString(R.string.notification_general_id),
getString(R.string.notification_general_name),
NotificationManager.IMPORTANCE_HIGH
);
nearbyAnchorsChannel.setDescription(getString(R.string.notification_general_desc));
// Register the channel with the system; you can't change the importance
// or other notification behaviors after this
NotificationManager notificationManager = getSystemService(NotificationManager.class);在GooglePixel3a上,通知只会震动并显示为左上角的一个点。然而,在OnePlus 6上,它显示为一个正确的提醒通知,我们可以立即滑动或点击。我试着查看我的Pixel 3a (它是Android 12)的设置,但是我找不到任何可以更改的选项来启用通知的提示显示。Tbh,我甚至不确定我的代码或者我正在测试的手机有什么问题。这是因为我的OnePlus 6的安卓版本(是安卓11)吗?还是因为我写的代码?如果这是由于前者,那么是否有人能向我解释,我如何可以改变设置在我的像素3a,以显示一个适当的可滑动抬头通知?
发布于 2022-03-15 13:40:12
我的错,当你改变频道的重要性,你需要卸载应用程序,并再次安装。这就是为什么它在OnePlus 6上工作(因为我在更改通知重要性之后安装了它),而不是在GooglePixel3a上工作(因为我仍然在使用相同的安装)。
https://stackoverflow.com/questions/71482843
复制相似问题