Reputation: 65870
Firebase API push payload from backend :
{
"registration_ids": [
"IKSiok9Zpip5cDcebQ67wc7TnpDuhMAFJm1xdGGI44s48JbXEu5iYa"
],
"notification": {
"body": "Push Test Facility Category",
"title": null,
"icon": "myicon",
"sound": "mySound",
"vibrate": 1,
"Badge": 1,
"click_action": "FCM_PLUGIN_ACTIVITY"
},
"data": {
"message": "Push Test Facility Category",
"title": null,
"b": "22",
"id": "2",
"category_name": "Restaurants",
"h": "1",
"p": 1,
"type": "2"
}
}
fcm.service.ts
fcmListeners() {
this.firebase.onNotificationOpen().subscribe(async (data: any) => {
if (data.tap) {// when user tapped the background notification
} else { // Received in foreground
}
});
}
Can you tell me why the app doesn't open when I used the above payload and app is in the background? This is the behavior on an Android device. But no issues on iOS device.
If I use a firebase console cloud message (i.e. dashboard) then no issues there. i.e. it opens the app even in the background on android device. Any clue?
Note: I use the firebase plugin here.
Upvotes: 0
Views: 3460
Reputation: 2266
The reply marked as the answer above might work, but it is not the ideal way of doing things on Android. The above problem occurs when android looks for an intent specified in the "ClickAction" of the backend push notification and does not find it. This will result in android not knowing what activity to use to handle the intent you specified in the notification and you'll have this message in your output window.
Notification pending intent canceled
The best way of handeling this, will be to precise in your notification a string value for "click_action" (Above we have "FCM_PLUGIN_ACTIVITY") Then if your manifest file, add an action filter for this intent while precising the "Default" category. As shown below
<activity
.... >
....
<intent-filter>
<action android:name="FCM_PLUGIN_ACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
If you are in Xamarin.Android, there is an easier way of doing this, Above your activity, just add the Intentfilter flag, and precise the name of your intent :
[IntentFilter(new []
{
"FCM_PLUGIN_ACTIVITY"
},
Categories=new[]
{
global::Android.Content.Intent.CategoryDefault
})]
public class MainActivity : ....
As mentioned in this comment.
Upvotes: 1
Reputation: 2117
And also defined your activity like this
<activity
android:name=".NotificationPushTapedActivity"
android:excludeFromRecents="true"
android:launchMode="singleTask"
android:parentActivityName=".MainActivity"
android:screenOrientation="portrait"
android:taskAffinity=""
android:theme="@style/Theme.AppCompat.DayNight.NoActionBar"
android:windowSoftInputMode="stateHidden">
<intent-filter>
<action android:name="CLICK_ACTION" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Upvotes: 0
Reputation: 44659
The issue is that the FCM_PLUGIN_ACTIVITY
activity may not be defined in the AndroidManifest.xml
or if it's defined there, it may not be implemented properly.
In order to fix it, don't specify the click_action
in the notification's payload - by default the notification will use the MainActivity
and that will open the app.
{
"registration_ids": [
...
],
"notification": {
...,
"click_action": "FCM_PLUGIN_ACTIVITY" // <--- Remove this
},
"data": {
...
}
}
Upvotes: 6