【问题标题】:Why don't notifications appear in the system tray?为什么通知不会出现在系统托盘中?
【发布时间】:2018-04-26 16:56:06
【问题描述】:

我可以在我的应用运行时向我的 Android 手机和模拟器发送推送通知。 (我可以说他们到达是因为我的应用程序崩溃了。)

那么为什么通知不会出现在系统托盘中呢?几个小时后,当我查看手机时,他们做了几次。我不知道为什么会这样。

我从 Firebase 云消息传递屏幕发送它们,它显示消息“已完成”。

这里有一些代码...

[Service]
    [IntentFilter(new[] { "com.google.firebase.INSTANCE_ID_EVENT" })]
    public class FirebaseIIDService : FirebaseInstanceIdService
    {
        const string TAG = "MyFirebaseIIDService";

        public override void OnTokenRefresh()
        {
            var refreshedToken = FirebaseInstanceId.Instance.Token;

            Log.Debug(TAG, "Refreshed token: " + refreshedToken);
        }
    }

    [Service]
    [IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })]
    public class CCFirebaseMessagingService : FirebaseMessagingService
    {
        public override void OnMessageReceived(RemoteMessage message)
        {
            Log.Debug(TAG, "Hi Mum!");
        }
    }

这两个事件都可以在调试器中中断。

在清单中...

<application android:label="My app">
        <receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" android:exported="false" />
        <receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND">
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
                <category android:name="${applicationId}" />
            </intent-filter>
        </receiver>
    </application>

【问题讨论】:

  • 你能出示你的代码吗!
  • 我们不是上帝!
  • 我想你是第一次尝试firebase
  • 好的,有些已经出现了。那么,通知什么时候出现在系统托盘中呢?是否仅当应用程序不可见运行时,或者如果应用程序不可见但出现在应用程序列表屏幕中,它们不会出现在系统托盘中?
  • 默认只有当应用在后台时才会出现!

标签: android firebase firebase-cloud-messaging


【解决方案1】:

这是 Firebase 的设计。

如果应用程序在后台,通知将显示,但如果它是可见的,则不会显示。底层推送消息的实际接收和通知的显示由 Firebase 库处理。

这与旧版 Google Cloud Messaging 不同,后者始终向应用程序提供前台或后台服务。

(基于长线程中的 cmets 的社区 wiki 答案。请编辑以添加更多详细信息。)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-09
    • 2012-02-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多