android tv can not receive fcm messages when device in standby

Offen
#761 0 Kommentare 0 Reaktionen 1 zugewiesene Person Auf GitHub ansehen

@kroikie arbeitet bereits daran.

Seit 17.12.2018.

Bewertung

Dieses Issue wurde noch nicht bewertet.

Beschreibung

api: messaging type: question

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) {
        // [START_EXCLUDE]
        // There are two types of messages data messages and notification messages. Data messages
        // are handled
        // here in onMessageReceived whether the app is in the foreground or background. Data
        // messages are the type
        // traditionally used with GCM. Notification messages are only received here in
        // onMessageReceived when the app
        // is in the foreground. When the app is in the background an automatically generated
        // notification is displayed.
        // When the user taps on the notification they are returned to the app. Messages
        // containing both notification
        // and data payloads are treated as notification messages. The Firebase console always
        // sends notification
        // messages. For more see: https://firebase.google.com/docs/cloud-messaging/concept-options
        // [END_EXCLUDE]

        // Not getting messages here? See why this may be: https://goo.gl/39bRNJ
        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();
        }
        // Also if you intend on generating your own notifications as a result of a received FCM
        // message, here is where that should be initiated. See sendNotification method below.
    }
    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?

Vorherrschende Sprache
Kotlin
Sterne
9.3k
Forks
7.4k
Ø Merge
7 T. 9 Std.
Gemergte PRs (30 T.)
6

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus firebase/quickstart-android

Alle Issues in firebase/quickstart-android

Ähnliche Issues

Weitere Issues zu Kotlin

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.