如何在Firebase中的后臺(tái)應(yīng)用時(shí)處理通知這是我的清單 <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>當(dāng)應(yīng)用程序處于后臺(tái)并且通知到達(dá)時(shí),默認(rèn)通知將會(huì)運(yùn)行并且不會(huì)運(yùn)行我的代碼onMessageReceived。這是我的onMessageReceived代碼。如果我的應(yīng)用程序在前臺(tái)運(yùn)行,而不是在后臺(tái)應(yīng)用程序時(shí),則調(diào)用此方法。如何在應(yīng)用程序處于后臺(tái)時(shí)運(yùn)行此代碼?// [START receive_message]@Overridepublic 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]
添加回答
舉報(bào)
0/150
提交
取消