When I send firebase cloud message, I touched the notification message in background of android device.
but app was not launched.
even if I set the click_action, and intent-filter in Manifest file.
I dont know what problem is.
I just want to launch app when I touch background push notification . but even if I touched background push notification, no launch the app
send message
{
"message": {
"android": {
"data": {
"scheme": "",
"payload": "null",
"background": "false",
"userId": "userId"
},
"notification": {
"body": "sdf",
"click_action": "DeepLinkHandlerActivity",
"default_light_settings": true,
"default_sound": true,
"default_vibrate_timings": true,
"title": "test"
}
},
"apns": {
"payload": {
"aps": {
"alert": {
"body": "sdf",
"title": "test"
},
"badge": 1,
"sound": "default"
}
}
},
"data": {
"scheme": "",
"payload": "null",
"userId": "b8ebe243-7d3b-41d8-b986-6abcb0fbdebf",
"background": "false"
},
"notification": {
"body": "sdf",
"title": "test"
},
"token": "tokendata"
}
}
Manifestfile
<activity
android:name=".ui.activity.login.SplashActivity"
android:label="@string/app_name"
android:exported="false"
android:screenOrientation="portrait"
>
<intent-filter>
<action android:name="DeepLinkHandlerActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
service in manifest file
<service
android:name=".firebase.MyFirebaseMessagingService"
android:exported="false"
android:directBootAware="true"
android:stopWithTask="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
3
Answers
FirevaseMessagingService.kt source file
did you create a service named FirebaseMessagingService or similarly named? if you have created it, you need to create intent and PendingIntent there and add it. If you do not have such a service, you need to prepare the service. While researching for you, I found a convenient example; https://www.geeksforgeeks.org/how-to-push-notification-in-android-using-firebase-cloud-messaging/
I examined the codes and there are 2 types of messages in Google Firebase Messaging, one of them is "notification" and the other is "data" and you have done data control on the code. How do you send the notification when you send it? Notification can be sent through the firebase panel, but the data message is sent only through the server. When sending a message, you need to check which of the "Notification" – "Data" you are sending. In the "Notification" notifications, the codes you wrote while the application is in the kill state will not work, but if you send a "Data" notification, the codes you wrote when the application is killed will also work. Therefore, if the notification you sent is "Notification", you need to change it to "Data". As I said, "Data" Notifications cannot be sent through the Panel, they are only sent from the server.