アプリが殺されると、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コンソールでは、メッセージを4週間オンラインにするように設定しましたが、動作しません。 – PAMAZ
これは奇妙です。 FCMの動作は、アプリケーション/デバイスが利用可能になるとすぐにメッセージを送信することです。これは、テストしたすべてのデバイスの動作ですか? –