meow
meow

Reputation: 1

Does FCM Messaging for Android apps support linking into the app

With Apple Push noitifications, there is a url parameter in the notification request that specifies where the app opens to when a user clicks the notification.

Is there an equivalent for android FCM notifications?

Upvotes: 0

Views: 87

Answers (2)

Arthur Thompson
Arthur Thompson

Reputation: 9225

With Android you have two FCM options here.

  1. Notification message with a click_action field set to the Activity that you want launched when the user taps on the auto generated notification.
  2. Data message where you will be able to generate your own notification specifying the pendingintent that will be fired when the notification is tapped by the user.

Upvotes: 0

josemgu91
josemgu91

Reputation: 719

You can send a custom value in the FCM message (a Data message) payload and then parse it in the device and create the notification with a custom click action according to the value of the custom field. For example this could be your method to build the notification:

private static Notification createNotification(final Context context, final String activity){
        final Class activityToLaunch;
        switch (activity){
            case "Activity1":
                activityToLaunch = Activity1.class;
                break;
            case "Activity2":
                activityToLaunch = Activity2.class;
                break;
            default:
                activityToLaunch = MainActivity.class;
        }
        final PendingIntent myAction = PendingIntent.getActivity(context, 1, new Intent(context, activityToLaunch), PendingIntent.FLAG_CANCEL_CURRENT);
        return new NotificationCompat.Builder(context)
                .setContentTitle("My Title")
                .setContentText("My Content")
                .setSmallIcon(R.drawable.my_icon)
                .setContentIntent(myAction)
                .build();
    }

Where the "activity" param is the value of the field you sent in your payload.

Upvotes: 1

Related Questions