0

Firebaseから通知を受け取りましたが、作成したクラスは動作していません(アクションには関係しません)。デフォルトで表示されているようです。MyFirebaseMessagingServiceは動作していませんが、通知が表示されます

public class MyFirebaseMessagingService extends FirebaseMessagingService { 

    @Override 
    public void onMessageReceived(RemoteMessage remoteMessage) { 

     String title = remoteMessage.getNotification().getTitle(); 
     String message = remoteMessage.getNotification().getBody(); 
     String click_action = remoteMessage.getNotification().getClickAction(); 
     Intent intent = new Intent(click_action); 
     intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
     PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT); 

     NotificationCompat.Builder notifiBuilder = new NotificationCompat.Builder(this) 

       .setContentTitle(title) 
       .setContentText(message) 
       .setAutoCancel(true) 
       .setContentIntent(pendingIntent); 

     NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); 
     notificationManager.notify(0, notifiBuilder.build()); 

    } 
} 

答えて

0

通知とデータの2種類のFCMメッセージがあります。それらは、受信装置において異なる方法で取り扱われる。データフィールドのない通知メッセージを送信する場合、通知はクライアントSDKによって生成され、onMessageReceived()は呼び出されません。これはexplained in more detail in the documentationです:

  • 通知メッセージ:FCMは、自動的にクライアントアプリケーションに代わってエンドユーザデバイスにメッセージが表示されます。通知メッセージ には、事前に定義されたユーザー可視キーのセットと、オプションのデータ カスタムキー/値ペアのペイロードがあります。

  • データメッセージ:クライアントアプリケーションはデータメッセージの処理を担当します。データメッセージには、カスタムのKey-Valueペアのみがあります。

関連する問題