As we know, tv has no system bar, so I just send data only messages, it works when messaging app is in foreground, background and even not runnning. But When I press "Power" key (with power instant on), the device will enter standby mode(str standby), I can promise the message has sent successfully:
{
"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"
}
]
}
And I can see the log:
broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE flg=0x10000000 pkg=com.tcl.fcmapp (has extras) }
When tv is in standby, I wake up the device by calling method like below:
/**
* 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();
}
}
I have read the docs about FCM, it says FCM support wake up the device, so is there anything wrong with my using ways?
User contributions licensed under CC BY-SA 3.0