我知道,當應用程序被殺時,它不能顯示任何Firebase通知...或者這是我的新應用程序會發生的情況:我殺了應用程序,新通知不會出現。在應用程序開始時檢索Firebase通知
現在,我想以新的方式擺脫這個問題:我想檢索,當我的應用程序啓動時,應用程序「忘記」看到的所有通知。
這裏是我的代碼
IdService
public class FirebaseIDService extends FirebaseInstanceIdService {
private static final String TAG = "FirebaseIDService";
@Override
public void onTokenRefresh() {
// Get updated InstanceID token.
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.d(TAG, "Refreshed token: " + refreshedToken);
// TODO: Implement this method to send any registration to your app's servers.
sendRegistrationToServer(refreshedToken);
}
/**
* Persist token to third-party servers.
*
* Modify this method to associate the user's FCM InstanceID token with any server-side account
* maintained by your application.
*
* @param token The new token.
*/
private void sendRegistrationToServer(String token) {
// Add custom implementation, as needed.
}
}
和消息類
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "FCM Service";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// TODO: 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.
Log.d(TAG, "From: " + remoteMessage.getFrom());
Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());
notifies(remoteMessage.getNotification().getBody());
}
private void notifies(String body){
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(MyFirebaseMessagingService.this)
.setSmallIcon(android.R.drawable.ic_menu_help)
.setContentTitle("Congratulations!")
.setContentText(body);
Notification mNot= mBuilder.build();
// Display
NotificationManager mNotMan = (NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);
mNotMan.notify(1,mNot);
}
}
你可以建議我什麼?感謝所有的答案:D
如果你不設置時間來留言,如果你的應用程序沒有得到它,那麼它永遠不會。你不能「得到所有錯過的信息」沒有這樣的事 – tyczj
好吧,所以我必須設定一個生活的時間,對吧?在Firebase控制檯上,我將消息設置爲在線四周,但不起作用... – PAMAZ
這很奇怪。 FCM的行爲是在應用程序/設備可用時立即發送消息。這是你測試過的所有設備的行爲嗎? –