android / user-interface-samples

Multiple samples showing the best practices in the user interface on Android.
Apache License 2.0
4.36k stars 1.64k forks source link

E/FirebaseMessaging: Notification pending intent canceled in android P #98

Open srigiri92 opened 5 years ago

srigiri92 commented 5 years ago

Im getting error "E/FirebaseMessaging: Notification pending intent canceled" while clicking on the notification,

this happens when the app is in background and push came try to open it getting the error, App also not opening. But all works fine in below P version even background works.

Any changes Do I need to-do in-order to support P version ?

hansemannn commented 5 years ago

Same here!

TheEnsis commented 5 years ago

me too even android O

edit : found the reason that my app was not opening when click notification in background mode is i added "click_action" in notification model when i send it. after remove it my app work normal.

ref : https://stackoverflow.com/questions/56924836/firebase-api-push-doesnt-open-background-app-on-android-device

ClarkNguyen commented 5 years ago

me too even android O

edit : found the reason that my app was not opening when click notification in background mode is i added "click_action" in notification model when i send it. after remove it my app work normal.

ref : https://stackoverflow.com/questions/56924836/firebase-api-push-doesnt-open-background-app-on-android-device

but if you remove that "click_action", you can't use both "notification" and "data" attributes at same time

akumar-atheer commented 4 years ago

Any update on this? I am facing the same problem.

robertofrontado commented 4 years ago

@akumar-atheer are you sending click_action? I faced the same issue today, problem was I was missing an intent-filter in the manifest for that particular action

<activity ...>
            <intent-filter>
                <action android:name=CLICK_ACTION />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
</activity>

Note: CLICK_ACTION will be whatever action you are sending

rami-alloush commented 3 years ago

Build on what everyone else said, there doesn't seem to be a bug here. When we remove the click_action from the notification payload, the system automatically opens the default activity that has the <intent-filter> e.g. MainActivity and sends the data part as intent extras. More on this here

When we do have the click_action we must have an <intent-filter> with the name set to that action, otherwise we get the mentioned error. A working example is the following.

From Firebase SDK

const notificationPayload = {
    notification: {
        title: 'Your title here',
        body: 'Your body here' ,
    },
    webpush: {
        notification: {
            icon: 'https://domain.com/logo.png',
        },
        fcmOptions: {
            link: `https://domain.com`,
        }
    },
    android: {
        "notification": {
            "click_action": "OPEN_PROFILE"
        }
    },
}

Inside AndroidManifest.xml

<activity
    android:name=".activity.ProfileActivity"
    android:screenOrientation="portrait">
    <intent-filter>
        <action android:name="OPEN_PROFILE" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>