Im sending a notification via the FCM legacy api like so:
// POST https://fcm.googleapis.com/fcm/send
{
"to": "<device-token>",
"notification": {
"title": "Test!",
"body": "testing",
"mutable_content": true,
"sound": "Tri-tone",
"click_action": "https://example.com/1234"
}
}
Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="cx.myapp.android">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="@style/AppTheme">
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@mipmap/ic_launcher" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/light" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="@string/default_notification_channel_id" />
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize"
android:screenOrientation="portrait"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" android:host="example.com" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
</manifest>
The notification is being received, but it does not launch the application when it’s clicked.
Interestingly, if I launch the application myself, the notification is received in the react-native linking event callbacks.
So its like everything is working except the app launching! Frustrating.
Note; deep links worked with the same url in "click_action" testing with adb shell am start -W -a android.intent.action.VIEW -d "https://example.com/some-deep-link" cx.myapp.android
.
Thanks!
EDIT:
I have tried adding the below to my manifest underneath my .MainActivity. Then I have tried sending the notification with "click_action": "TESTING" with no luck.
<activity
android:name="TESTING"
android:exported="true">
<intent-filter>
<action android:name="TESTING" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
2
Answers
The issue might be the intent-filter created for the Activity, here’s how it should look:
As you can see the value of the key click_action should be the same as the one in
<action android:name="the same value">
of the intent filter.Also, it might be because of the
<category android:name="android.intent.category.BROWSABLE" />
, you might try to remove it.Remember to define a PendingIntent for the notification
Then set the PendingIntent to the Notification