0

我的應用程序正在運行我只是屏蔽了設備,並且沒有通知事件進入FirebaseMessagingServiceOn Screen Off 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

如果您收到通知時,您的應用程序是在前臺,那麼你應該得到它時,它是在後臺發生火災後通知的應用程序。你使用什麼設備? –

回答

0

您的代碼是正確的。您只需將priority設置爲從您的服務器發送的消息,並將其設置爲high。在您的服務器端添加以下關鍵的消息:

"priority" : "high", 

並且通知開始在android結束工作。

+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