设备待机时,Android电视无法接收fcm消息

时间:2018-12-06 02:16:14

标签: android firebase firebase-cloud-messaging android-tv television

我们知道,电视没有系统栏,所以我只发送数据消息,当消息传递应用程序处于前台,后台甚至不运行时它都可以工作。但是当我按下“电源”键(打开电源瞬间)时,设备将进入待机模式(str待机),我可以保证消息已成功发送:

{
 "to" : "xxx",
 "collapse_key" : "tv",
 "priority": "high",
 "content_available":true,
 "data" : {
     "body" : "wake up"
 }
}

{
    "multicast_id": xxx,
    "success": 1,
    "failure": 0,
    "canonical_ids": 0,
    "results": [
        {
            "message_id": "xxx"
        }
    ]
}

我可以看到日志:

broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE flg=0x10000000 pkg=com.tcl.fcmapp (has extras) }

当电视处于待机状态时,我通过调用如下方法唤醒设备:

/**
 * Called when message is received.
 *
 * @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
 */
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    Log.d(TAG, "From: " + remoteMessage.getFrom());

    // Check if message contains a data payload.
    if (remoteMessage.getData().size() > 0) {
        Log.d(TAG, "Message data payload: " + remoteMessage.getData());
        wakeUpScreen();
    }
}

private void wakeUpScreen() {
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    @SuppressLint("InvalidWakeLockTag") PowerManager.WakeLock wakeLock = pm.newWakeLock
            (PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "LiveTV");
    wakeLock.setReferenceCounted(false);
    try {
        wakeLock.acquire();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

我已经阅读了有关FCM的文档,其中说FCM支持会唤醒设备,所以我的使用方式有什么问题吗?

0 个答案:

没有答案