0

私のアンドロイドアプリケーションでFCM通知を使用しています。アプリケーションがバックグラウンドになると、通知のクリックはMainActivityにナビゲートします。これは通知が1つしかない場合にのみ発生します。複数の通知がある場合は、最後の通知だけがアプリケーションを起動できます。 アプリがフォアグラウンドになったら、通知のクリックは行われません。アプリを閉じて通知バーから次の通知をクリックすると、アプリが再び開きます。Androidで多数のプッシュ通知を処理する

通知ペイロードに通知アクションに問題があると思います。

<application 
    android:name=".MyApplication" 
    android:allowBackup="false" 
    android:icon="@mipmap/ic_launcher" 
    android:launchMode="singleTop" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" 
    tools:replace="android:allowBackup"> 

    <!-- tools:replace="android:theme" --> 
    <!-- Launch Flow --> 
    <activity 
     android:name=".ui.activity.MainActivity" 
     android:screenOrientation="portrait" 
     android:theme="@style/SplashTheme"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 

     <intent-filter> 
      <action android:name="myAction" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
     </intent-filter> 
    </activity> 


    <!-- [START firebase_service] --> 
    <service android:name=".service.MyFirebaseMessagingService"> 
     <intent-filter> 
      <action android:name="com.google.firebase.MESSAGING_EVENT" /> 
     </intent-filter> 
    </service> 
    <!-- [END firebase_service] --> 


    <!-- [START firebase_iid_service] --> 
    <service android:name=".service.MyFirebaseInstanceIDService"> 
     <intent-filter> 
      <action android:name="com.google.firebase.INSTANCE_ID_EVENT" /> 
     </intent-filter> 
    </service> 
    <!-- [END firebase_iid_service] --> 


</application> 

これは私の通知jsonです。すべての通知が同じtagを持っている場合

{ 

"notification":{ 
    "title":"Jogn Doe", 
    "body":"Jogn commented on your post", 
    "sound":"mySound", 
    "tag":"88211407420864", 
    "click_action":"myAction" 
}, 
"data":{ 
    "notificationCount":2, 
    "creatorName":"John Doe", 
    "creatorImage":"https://image.com/sample.png", 
    "notificationId":"88335540289536", 
    "universityId":"8821098664448" 
}, 
    "to":"fYu_ybp3Wu8:APA91bHxOact-9gcqf7rAqNSPSkvU7N5h4t4m0XgCAHBdu" 
} 

私はのonCreateメソッドでこれを行う。..

Intent intent = new Intent(LauncherActivity.this, PostFeedActivity.class); 
    if (getIntent().getAction().equalsIgnoreCase("myAction")) { 
     Bundle extras = getIntent().getExtras(); 
     String universityId = extras.getString(getString(R.string.notification_university)); 

     String notificationId = extras.getString(getString(R.string.notification_id)); 
     String notificationCreatorName = extras.getString(getString(R.string.notification_creator_name)); 
     String notificationCreatorImage = extras.getString(getString(R.string.notification_creator_image)); 
     int notificationCount = extras.getInt(getString(R.string.notification_count), 0); 
     if (!TextUtils.isEmpty(notificationId)) { 
      intent.setAction(getString(R.string.action_notification_from_push)); 

      intent.putExtra(getString(R.string.notification_count), 
        notificationCount); 
      intent.putExtra(getString(R.string.notification_id), 
        notificationId); 
      intent.putExtra(getString(R.string.notification_creator_name), 
        notificationCreatorName); 
      intent.putExtra(getString(R.string.notification_creator_image), 
        notificationCreatorImage); 

      //fetch notification data by calling API and start activity 
      requestNotification(notificationId, intent); 
      // 

     } else { 
      startActivity(intent); 
      finish(); 
     } 

答えて

0

は、彼らがアンドロイドでグループ化され、その後、あなただけの最新の通知を持っています。 tagがユニークな値であるかどうかは、コードからわかりません(デバイスの通知バーに並べて表示されます)。

とすぐにnotificationオブジェクトを持っていないだけでdataとして、Androidは通知の一部を制御します、意味:

  • をあなたのアプリケーションが実行されていないか、バックグラウンドで、通知は通知バーに表示されている場合
  • あなたのアプリがフォアグラウンドでアクティブになっている場合は、なし通知が示され、代わりに、コールバックonMessageReceivedコールバックは(これはあなたがFCMからのデータのみのメッセージを受信した場合にも呼び出されるコールバックです)、あなたのFirebaseMessagingServiceで直接呼び出されます
  • アプリがフォアグラウンドにあるとき

は、通知が正常に動作している、ここにもこのことができますFCM notification merge

希望、 歓声

+0

を参照してください。しかし、私の問題は、アプリがバックグラウンドにあるときに表示されます。 **タグ**はユニークです。 –

+0

あなたは '' myAction''にコードを表示できますか?クリックをどのように処理しますか? – Grisgram

+0

私はそれを私の質問に追加しました:) –

関連する問題