Wie wird mit Benachrichtigungen umgegangen, wenn sich die App im Hintergrund in Firebase befindet?

ier ist mein Manife

    <service android:name=".fcm.PshycoFirebaseMessagingServices">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>

    <service android:name=".fcm.PshycoFirebaseInstanceIDService">
        <intent-filter>
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
        </intent-filter>
    </service>

Wenn sich die App im Hintergrund befindet und eine Benachrichtigung eingeht, kommt die Standardbenachrichtigung und führt meinen Code von @ nicht auonMessageReceived.

Hier ist meinonMessageReceived code. Dies ruft auf, wenn meine App im Vordergrund ausgeführt wird, nicht, wenn die App im Hintergrund ausgeführt wird. Wie kann ich diesen Code ausführen, wenn sich die App auch im Hintergrund befindet?

// [START receive_message]
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    // TODO(developer): Handle FCM messages here.
    // If the application is in the foreground handle both data and notification messages here.
    // 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.
    data = remoteMessage.getData();
    String title = remoteMessage.getNotification().getTitle();
    String message = remoteMessage.getNotification().getBody();
    String imageUrl = (String) data.get("image");
    String action = (String) data.get("action");
    Log.i(TAG, "onMessageReceived: title : "+title);
    Log.i(TAG, "onMessageReceived: message : "+message);
    Log.i(TAG, "onMessageReceived: imageUrl : "+imageUrl);
    Log.i(TAG, "onMessageReceived: action : "+action);

    if (imageUrl == null) {
        sendNotification(title,message,action);
    } else {
        new BigPictureNotification(this,title,message,imageUrl,action);
    }
}
// [END receive_message]

Antworten auf die Frage(44)

Ihre Antwort auf die Frage