Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Firebase通知未显示在前台_Android_Firebase_Kotlin_Firebase Cloud Messaging - Fatal编程技术网

Android Firebase通知未显示在前台

Android Firebase通知未显示在前台,android,firebase,kotlin,firebase-cloud-messaging,Android,Firebase,Kotlin,Firebase Cloud Messaging,我正在尝试管理通知,但当应用程序位于前台时,我无法对它们执行任何操作 当应用程序最小化或完全关闭时,通知会正确显示,但如果应用程序位于前台,则不会看到通知 我对这段代码进行了测试,但没有任何效果。应用程序关闭或最小化的通知可通过修改此代码或使用任何此代码来工作: (根据注释指示编辑,结果相同) 并表明: <service android:name="PACKAGE_NAME.servicios.ServicioNotificaciones"

我正在尝试管理通知,但当应用程序位于前台时,我无法对它们执行任何操作

当应用程序最小化或完全关闭时,通知会正确显示,但如果应用程序位于前台,则不会看到通知

我对这段代码进行了测试,但没有任何效果。应用程序关闭或最小化的通知可通过修改此代码或使用任何此代码来工作:

(根据注释指示编辑,结果相同)

并表明:

   <service
            android:name="PACKAGE_NAME.servicios.ServicioNotificaciones"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
    </service>

谢谢大家

您必须使用通知频道:

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    val notificationChannel = NotificationChannel(
        "notify_001",
        getString(R.string.notification_channel_name),
        NotificationManager.IMPORTANCE_HIGH)

    mNotificationManager.createNotificationChannel(notificationChannel)
}

我看不出在哪里创建通知通道(因为Android O是必须的)


我认为这个问题与发送通知相关,不接收通知尝试这样发送通知

"data": {
  "data_title": "test",
  "data_body" : "test"
 }

谢谢,但它不起作用:((我试图在这里包含代码…)你在日志中找到任何异常吗?不,我一步一步地调试,没有看到任何异常。你能不能也发布通知负载?什么是通知负载?我通过Firebase控制台发送通知。Ì没有。但是我通过你的链接步骤和@Md.Asaduzzaman指示添加了这个,但对我不起作用。不,它没有总是收到通知,只是它没有显示在前景中。我最终修复了它。非常感谢!@msolla你能解释一下你是如何修复的吗this@Saurabh我用对我有效的修复方法修改了最初的问题,查看编辑2:)(原谅反应迟钝)
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    val notificationChannel = NotificationChannel(
        "notify_001",
        getString(R.string.notification_channel_name),
        NotificationManager.IMPORTANCE_HIGH)

    mNotificationManager.createNotificationChannel(notificationChannel)
}
"data": {
  "data_title": "test",
  "data_body" : "test"
 }