Wie man mit der Benachrichtigung arbeitet, wenn die App im Hintergrund in Firebase läuft

Hier ist mein manifest

    <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 die app im hintergrund läuft, und die Benachrichtigung kommt dann die Standard Meldung kommt und nicht mit meinem code von onMessageReceived.

Hier ist mein onMessageReceived code. Dies ruft, wenn meine app läuft auf Vordergrund, und nicht, wenn app im hintergrund. Wie um diesen code auszuführen, wenn die app im hintergrund zu?

//[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]

InformationsquelleAutor der Frage Parth Patel | 2016-06-08

Schreibe einen Kommentar