2017-06-20 11 views
1

私は助けが必要です。 Firebase通知がバックグラウンドで動作していません。これは私のコードです:あなたはyoourサーバーコードから通知リクエストボディの変更を行う場合を除きアプリがバックグラウンドで動作しているときFirebase通知がバックグラウンドで動作しない

@Override 
public void onMessageReceived(RemoteMessage remoteMessage) { 

    Log.d(TAG, "FROM:" + remoteMessage.getFrom()); 
    sharedPreference = getSharedPreferences(Global.SECURETRADE, 0); 
    UID = sharedPreference.getString(Global.ID, ""); 


     Uri defaultSoundUri=RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)`enter code here`; 

     NotificationCompat.Builder notificationBuilder = new 
       NotificationCompat.Builder(this); 

     if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 

      notificationBuilder.setSmallIcon(R.mipmap.small_secure_trade_app_icon); 

     } else { 

      notificationBuilder.setSmallIcon(R.drawable.small_secure_trade_app_icon); 
     } 

     notificationBuilder.setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.securetrade_icon)); 
     notificationBuilder.setContentTitle(remoteMessage.getData().get("title")); 
     notificationBuilder.setContentText(remoteMessage.getData().get("body")); 
     notificationBuilder.setAutoCancel(true); 
     notificationBuilder.setSound(defaultSoundUri); 
     notificationBuilder.setContentIntent(pendingIntent); 

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

     notificationManager.notify(0, notificationBuilder.build()); 

    } 




} 
+0

どのようにメッセージを送信していますか? –

+0

また、正常に動作する前に、同じことが疑われています –

+0

なぜ動作していないのか不思議です、Firebaseには多くのエラーが出ていますwokring perviously –

答えて

0

アプリはバックグラウンドで動作しているか、通知のためのデータペイロードを使用する必要が殺されたとき。背景onMessageReceiveで実行中のアプリはちょうどあなたのランチャーの活動にコードのこの平和をコピーして、それをチェックしランチャー活動に来

オフラインメッセージを動作しません Firebase onMessageReceived not called when app in background

-1

。それが動作します。

Bundle bundle = getIntent().getExtras(); 
    if (bundle != null) { 
     Logger.info(TAG, "FIRE BASE OFF LINE NOTIFICATIONS COMING TO THIS BLOCK--->"); 

     JSONObject json = new JSONObject(); 
     Set<String> keys = bundle.keySet(); 
     for (String key : keys) { 
      Logger.info(TAG, "json object--->" + key + "---values--" + JSONObject.wrap(bundle.get(key))); 
     } 
    } 

とあなたのペイロードがこの

{ "notification": { 
    "title": "Your Title", 
    "text": "Your Text", 
    "click_action": "OPEN_ACTIVITY_1" // should match to your intent filter 
    }, 
    "data": { 
    "keyname": "any value " //you can get this data as extras in your activity and this data is optional 
    }, 
    "to" : "to_id(firebase refreshedToken)" 
} 

reference

0

ようにする必要がありますが、あなたはデータ・メッセージ(ない通知メッセージ)を送信していますか?あなたはFCMがあなたのクライアントアプリケーションの代わりに 通知を表示処理したいとき

通知メッセージがonMessageReceived()

使用通知メッセージを呼び出すことはありません。 がクライアントアプリケーションでメッセージを処理したいときにデータメッセージを使用します。もっとここに

読む:https://firebase.google.com/docs/cloud-messaging/concept-options#notifications_and_data_messages

PS:あなたはデータ・メッセージを送信している、とonMessageReceived()が呼び出されない場合FCM Webコンソールが常に通知メッセージ


を送信します。.. 。
それは別の問題です。

この特定のデバイスの問題である可能性もあります。
Push notifications using FCM not received when app is killed android

関連する問題