首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android通知不会显示为提示通知

Android通知不会显示为提示通知
EN

Stack Overflow用户
提问于 2022-03-15 13:10:29
回答 1查看 587关注 0票数 0

我使用以下代码来显示我的通知:

代码语言:javascript
复制
    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());

我使用以下代码创建通知通道:

代码语言:javascript
复制
    // 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,以显示一个适当的可滑动抬头通知?

EN

回答 1

Stack Overflow用户

发布于 2022-03-15 13:40:12

我的错,当你改变频道的重要性,你需要卸载应用程序,并再次安装。这就是为什么它在OnePlus 6上工作(因为我在更改通知重要性之后安装了它),而不是在GooglePixel3a上工作(因为我仍然在使用相同的安装)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71482843

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档