0
我在我的android應用程序中使用FCM通知。當應用程序在後臺時,通知單擊導航到MainActivity。只有當只有一個通知時纔會發生這種情況。當有多個通知時,只有最後一個通知才能啓動應用程序。 一旦應用程序進入前臺,通知點擊不會發生。如果我關閉應用程序並單擊通知欄中的下一個通知,則應用程序會再次打開。處理多個推送通知在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。
{
"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();
}
當應用程序是在前臺,通知是否正常工作。但是當我的應用程序在後臺運行時出現我的問題。 **標籤**是獨一無二的。 –
你可以在myAction中顯示代碼嗎?你如何處理點擊? – Grisgram
我加我的問題:) –