【发布时间】:2017-12-07 15:10:11
【问题描述】:
我在我的 android 应用程序中使用 FCM 通知。当应用程序处于后台时,通知单击导航到 MainActivity。只有当只有一个通知时才会发生这种情况,当有多个通知时,只有最后一个通知才能启动应用程序。 一旦应用程序进入前台,通知点击就不会发生。如果我关闭应用程序并单击通知栏中的下一个通知,则应用程序会再次打开。
我认为通知负载中的通知操作存在问题。
<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();
}
【问题讨论】:
标签: android firebase push-notification notifications firebase-cloud-messaging