Android 通知未显示在 API 级别 16 上

标签 android firebase notifications firebase-cloud-messaging

我正在尝试在我的 Android 应用程序中向用户显示通知。我现在正在运行两个模拟器。一个在 API 级别 16 上运行,另一个在 API 级别 25 上运行。当我向应用程序发送通知时,该通知只会显示在运行 API 级别 25 的模拟器上。我希望能够在运行 API 级别 16 的模拟器上显示通知。

这是我向用户显示通知的代码:

private void basicNotification(String title, String body, String data, Context context) {
    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(context)
                    .setSmallIcon(R.drawable.ic_monetization_on)
                    .setContentTitle(title)
                    .setContentText(body);

    NotificationManager mNotifyMgr =
            (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    // Builds the notification and issues it.
    mNotifyMgr.notify(0, mBuilder.build());
}

参数说明:

标题 = 通知的标题。

body = 通知正文。

data = 通知的数据(尚未使用)。

context = 这是我用来显示通知的上下文。此上下文是从扩展 FirebaseMessagingService 的类接收的。

当我执行上面的代码时,我不会收到任何错误。唯一会出现的内容是在 logcat 中。将出现以下行:

05-11 07:47:42.169 1606-1758/system_process D/ConnectivityService: handleInetConditionHoldEnd: net=0, condition=100, published condition=100

我不确定我现在做错了什么。我用了official documentation from Android来制作这个方法。如果您需要更多信息来解决问题,请告诉我:)

最佳答案

所以,在尝试了一些事情之后,我发现我犯了一个可怕的错误。通知已显示,但仅显示在下拉菜单中。对于遇到此问题的任何人,请尝试检查下拉菜单中是否有通知。

相关答案:https://stackoverflow.com/a/43809420/4653908

关于Android 通知未显示在 API 级别 16 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43909712/

相关文章:

android - GridView.LayoutParams 不存在,Android 代码中断

android - 如何找到启动状态栏通知的应用程序

android - 如何解析三个DateTIme

android - "Request Desktop Site"与 Xamarin Android 中的 Intent

android - Kotlin + 数据绑定(bind)在输入 '??' 处没有可行的替代方案

ios - 如何在 Firestore 中构建搜索列表?

android - 如何使用 Firebase 分析跟踪 android fragment

android - 完全空的应用程序上的 "Default FirebaseApp is not initialized in this process"

python - 使用 python 的带有按钮的 Windows 通知

java - 需要通知/仪表板系统的框架吗?