Ahmet Özrahat
Ahmet Özrahat

Reputation: 335

FCM notification "click_action" not working

I'm using a Cloud Function and sending push notifications with it. Sending notification works as expected but click_action attribute not working. When I click the notification nothing happens. Here is my code:

My notification payload:

const payload = {
  notification: {
      title: 'Soru Çözüm',
      body: 'Attığınz soruya bir yorum geldi: ' + data.content,
      icon: 'ic_stat_logo',
      click_action: '.activities.SoruDetayActivity'
  },
  data: {
      title: 'Soru Çözüm',
      content: 'Sorunuz çözüldü.',
      post: data.parent
  }
};

Intent Filter:

<activity
    android:name=".activities.SoruDetayActivity"
    android:label="Soru"
    android:windowSoftInputMode="adjustResize">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <action android:name=".activities.SoruDetayActivity"/>

        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />

        <data
            android:host="www.website.com"
            android:scheme="https" />
    </intent-filter>
</activity>

Upvotes: 3

Views: 5554

Answers (4)

gevge
gevge

Reputation: 398

For me, the problem is the Android Studio cache. Clear project and rebuild fix it. The string of android:name doesn't matter. My Android Studio version is Chipmunk | 2021.2.1 Patch 1

Upvotes: 0

MariosP
MariosP

Reputation: 9113

Your notification payload it seems correct. Try to change your intent filter by removing the data and category.BROWSABLE tags like the below lines of code:

<activity
    android:name=".activities.SoruDetayActivity"
    android:label="Soru"
    android:windowSoftInputMode="adjustResize">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <action android:name=".activities.SoruDetayActivity"/>

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

Upvotes: 1

Rajan Kali
Rajan Kali

Reputation: 12953

Notification will try to launch the URL, the specified activity name does not qualify as URL, so Android won't perform anything as it doesn't recognise, instead if you use the host address mentioned in your <data> tag in Manifest, it should redirect you to that Activity, something like below

click_action: 'https://www.website.com'

Upvotes: 0

Doug Stevenson
Doug Stevenson

Reputation: 317868

Your action name should be the full name of the activity to launch. What you have now is the partial name, relative to the name of your app's package. We can't see what that is here, since the prefix is elsewhere in your manifest. Once you find it, it should look more like this:

  click_action: 'com.yourapp.activities.SoruDetayActivity'

Upvotes: 0

Related Questions