How to open Target Activity using firebase Notification in android application?

194
January 22, 2018, at 4:16 PM

successfully send notification on my apps , but can't open target activity. when i click my notification it's open MainActivity.java. I want to open my target activity. Thanks.

Answer 1

As the documentation says:

When your app is in the background, Android directs notification messages to the system tray. A user tap on the notification opens the app launcher by default.

This includes messages that contain both notification and data payload (and all messages sent from the Notifications console). In these cases, the notification is delivered to the device's system tray, and the data payload is delivered in the extras of the intent of your launcher Activity.

So, you can check the extras in onCreate() method of your MainActivity.java and if it's from firebase, then open the target activity and finish the main activity.

Answer 2

Add "click_action": "ACTIVITY_FILTER_NAME" in notification array to your JSON payload from the firebase console.

Sample Json payload:

{
  "registration_ids": [
    "XXX",
    ...
  ],
  "data": {
    "id_offer": "100"
  },
  "notification": {
    "title": "This is the Title",
    "text": "This is the message"
    "click_action": "ACTIVITY_FILTER_NAME"
  }
}

Then, add the filter to the activity you want to handle the notification by default using

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

This will open the target activity and also passes on the payload of notification

READ ALSO
Firebase to RecyclerView: No adapter attached; skipping layout

Firebase to RecyclerView: No adapter attached; skipping layout

I have searched for this error in stack overflow and tried all the methods but i can get the solution and here is what I did:

224
How to use the method fyiWillBeAdvancedByHostKThx () in AdapterViewFlipper?

How to use the method fyiWillBeAdvancedByHostKThx () in AdapterViewFlipper?

I have been playing around with AdapterviewFlipper and I saw this function: https://developerandroid

114
How to prevent Screen Capture in Android

How to prevent Screen Capture in Android

Is it possible to prevent the screen recording in Android Application?

178