打开应用程序时,Firebase Cloud Messaging不显示通知栏

编程入门 行业动态 更新时间:2024-10-26 08:23:09
本文介绍了打开应用程序时,Firebase Cloud Messaging不显示通知栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我尝试通过在Firebase云消息传递中通过控制台发送通知来测试我的应用程序,但是当我的应用程序处于前台或仍在运行时.通知不会显示在设备中,并且触发了Firebase消息传递服务中的日志.

I tried to test my app with sending the notification via console in firebase cloud messaging, But when my app in the foreground or still running. The notification do not show in the device and the log in the firebase messaging service is triggered.

但是当我销毁我的应用程序时,通知运行良好.

But when i destroy my app, the notification work nicely.

这是我的清单

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="schemas.android/apk/res/android" xmlns:tools="schemas.android/tools" package="com.example.yehezkiel.eclassapp"> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <application android:allowBackup="true" android:icon="@mipmap/eclass_logo1" android:label="@string/app_name" android:roundIcon="@mipmap/eclass_logo1" android:supportsRtl="true" android:theme="@style/AppTheme" tools:replace="android:icon"> <service android:name=".myFirebaseInstanceTokenID"> <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT"/> </intent-filter> </service> <activity android:name=".LoginActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".MainActivity" /> <activity android:name=".Tugas" /> <activity android:name=".DetailActivity" android:label="@string/title_activity_detail" android:theme="@style/AppTheme" /> <activity android:name=".NilaiActivity" /> <activity android:name=".BaseActivity" /> <activity android:name=".MateriActivity" /> <activity android:name=".NilaiDetailActivity" /> <activity android:name=".PesertaActivity"></activity> </application> </manifest>

这是我的firebasemessaging服务

This my firebasemessagingservice

public class myFirebaseInstanceTokenID extends FirebaseMessagingService { private static final String TAG = "FirebaseMessagingServce"; @Override public void onMessageReceived(RemoteMessage remoteMessage) { if (remoteMessage.getData().size() > 0) { Log.e(TAG, "Message data payload: " + remoteMessage.getData()); } Log.e(TAG, "Tidak ada Data"); } }

推荐答案

您正在观察的是通知类型消息在Android上的工作方式.当您的应用程序位于前台时,您将在托盘中看不到任何通知.

What you're observing is is how notification type messages work on Android. When your app is in the foreground, you will not see a notification in the tray.

请阅读有关处理消息的文档以了解内容期待.特别是请参阅摘要"框,该框告诉您应用程序的前台状态和后台状态之间的消息处理有何不同.并不是说当您的应用程序处于前台时,您只能期望您的消息将在 onMessageReceived 中显示.如果需要,您可以在那里自己构造一个通知.

Please read the documentation on handling messages to understand what to expect. Especially see the "in summary" box that tells you how message handling is different between foreground and background states of your app. Not that when your app is in the foreground, you can only expect that your message will be seen in onMessageReceived. You can construct a notification there yourself, if needed.

更多推荐

打开应用程序时,Firebase Cloud Messaging不显示通知栏

本文发布于:2023-11-27 03:25:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636373.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   通知   Cloud   Firebase   Messaging

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!