打开应用程序时,Firebase Cloud Messaging不显示通知栏 [英] Firebase Cloud Messaging not showing notification bar when app is open

查看:38
本文介绍了打开应用程序时,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="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/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不显示通知栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆