0

私のアプリが実行されています。私はデバイスをスクリーンオフし、通知イベントはFirebaseMessagingServiceの中に来ません。オンスクリーンオフFCMが通知を失う

通知は通知トレイにも表示されません。 FCMのバグか、何か間違っていますか?

FCMServiceの添付コードを見つけてください。

public class FCMService extends FirebaseMessagingService { 
    private static final Logger LOGGER = LoggerFactory.createLogger(FCMService.class); 

    @Override 
    public void onMessageReceived(RemoteMessage message) { 
     if (null != message) { 
      onNotificationReceived(message.getNotification(), message.getData()); 
     } 
    } 

    /** 
    * Create and show a simple notification containing the received FCM message. 
    * @param messageBody FCM message body received. 
    * @param data Notification Data 
    */ 
    private void onNotificationReceived(RemoteMessage.Notification messageBody, final Map<String, String> data) { 
     LOGGER.info("Notification received... for data %s", data); 
     if (AppPreferences.getInstance().isUserLogin()) { 
      if (null != messageBody) { 
       LOGGER.info("Notification received... Foreground Notification...%"); 
      } else { 
       LOGGER.info("Notification received... Silent Notification...%");  
      } 
     } 
    } 
} 
+0

ようfirebaseからメッセージを取得した後、アプリであなたの火通知をしました。どのようなデバイスを使用していますか? –

答えて

0

コードは正しいです。サーバーから送信されたメッセージにpriorityを設定し、highに設定するだけです。あなたのサーバーでは、メッセージに以下のキーを追加します。

"priority" : "high", 

アンドロイドエンドで通知が開始されます。あなたのアプリがフォアグラウンドにあるときに通知を受信して​​いる場合

+0

私はこれを試してみましょう。 – Avi

+0

優先順位が高くても動作しません。 – Avi

0

は、それがバックグラウンドで動作しているとき、あなたはそれを受け取るべき

public void showNotification(String msg) 
{ 
    Intent intent = new Intent(this, Home.class); 
    PendingIntent pIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), intent, 0); 

    // Build notification 
    // Actions are just fake 
    Notification noti = new Notification.Builder(this) 
      .setContentTitle("title") 
      .setContentText(msg).setSmallIcon(R.drawable.original_logo) 
      .setContentIntent(pIntent) 
      .addAction(R.drawable.original_logo, "Call", pIntent) 
      .addAction(R.drawable.original_logo, "More", pIntent) 
      .addAction(R.drawable.original_logo, "And more", pIntent).build(); 
    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
    // hide the notification after its selected 
    noti.flags |= Notification.FLAG_AUTO_CANCEL; 

    notificationManager.notify(0, noti); 

} 
+0

あなたは何を言っているのか分かりませんが、私はonMessageReceivedのfirebaseからのコールバックを取得していません。 – Avi

関連する問題