2

終了時またはバックグラウンドで通知を受信しない。下は、通知を処理するMyサービスクラスです。 唯一のアプリが実行されているときに通知が機能しています。火災通知がバックグラウンドで受信されない、またはアプリが終了したとき

public class MyFirebaseMessagingService extends FirebaseMessagingService { 

    private static final String TAG = "MyFMService"; 
    Random random = new Random(); 
    int NOTIFICATION_ID = random.nextInt(9999 - 1000) + 1000; 

    @Override 
    public void onMessageReceived(RemoteMessage remoteMessage) { 
     sendNotification(); 


    } 

    private void sendNotification() { 
     Intent intent = new Intent(this, NotificationDisplay.class); 
     intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
     PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 
       PendingIntent.FLAG_ONE_SHOT); 

     Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
     NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) 
       .setSmallIcon(R.drawable.ic_bouddha_icon) 
       .setContentTitle("Bouddha Meridian School") 
       .setAutoCancel(true) 
       .setSound(defaultSoundUri) 
       .setContentIntent(pendingIntent); 

     NotificationManager notificationManager = 
       (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 

     notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build()); 
    } 
} 
+0

通知コンソールまたはサーバーの送信方法は? –

答えて

0

アプリがバックグラウンドのときメッセージクイズクラスはヒットしませんので、ペイロードをペイロードする際にサーバからハンドオーバする必要があります。

{ 
    "to" : "zzzzz", 
    "notification": { 
    "body": "", 
    "title": "", 
    "icon": "" 
}, 
"data" : { 
"name" : "" 

} 
    } 
関連する問題