我正在使用FCM進行通知,並且它在前臺和後臺的所有場景中運行良好。我的問題是,當我從我的應用程序註銷並且另一個用戶向我發送消息時,我沒有收到任何通知,因爲我註銷時沒有問題,但是當我再次登錄到應用程序時,我想要收到舊的未讀通知,以便如何這樣做的任何幫助,將不勝感激下面是我用從fcm獲取舊通知Android
public class FirebaseIDService extends FirebaseInstanceIdService {
private static final String TAG = "FirebaseIDService";
Context ctx = this;
@Override
public void onTokenRefresh() {
// Get updated InstanceID token.
try {
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.d(TAG, "Refreshed token: " + refreshedToken);
} catch (Exception e) {
e.printStackTrace();
}
}
}
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "FCM Service";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
Log.e("remote", remoteMessage.getData().get("type") + "");
Log.e("remoteMessage", remoteMessage.getData() + "");
Log.e("remoteMessagebody", remoteMessage.getData().get("body") + "");
// handling other data also according to my app which i am not mentioning
}
}
我已經使用這個代碼獲取老的通知,但因此未工作
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
和清單
<service
android:name=".MyFirebaseMessagingService"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service android:name=".FirebaseIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
代碼
和gradle這個
compile 'com.google.firebase:firebase-messaging:9.2.1'
您從後臺得到通知,PHP是指接到通知? – Saif