Deep Link with Push Notification - FCM - Android
Deep Link with Push Notification - FCM - Android
What I want: I want to send push notification to users. When user tap on that notification, user should navigate to specific activity.
What I did: I created one deep link in Firebase console. I implemented FirebaseInstanceIdService & FirebaseMessagingService as well. I'm able to catch Firebase message which I sent from Firebase console.
What is the issue: I'm not able to catch the dynamic link what I have created in Firebase console.
My code is like below.
MyFirebaseInstanceIDService.java
public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
private final String TAG = "MyFirebaseInstanceID";
@Override
public void onTokenRefresh() {
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.e(TAG, "Refreshed token: " + refreshedToken);
}
}
MyFirebaseMessagingService.java
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private final String TAG = "MyFbaseMessagingService";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
String message = remoteMessage.getNotification().getBody();
Log.e(TAG, "nmessage: " + message);
sendNotification(message);
}
private void sendNotification(String message) {
Intent intent = new Intent(this, TestDeepLinkActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setAutoCancel(true)
.setContentTitle("FCM Test")
.setContentText(message)
.setSound(defaultSoundUri)
.setSmallIcon(R.drawable.common_google_signin_btn_icon_dark)
.setContentIntent(pendingIntent);
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
manager.notify(0, builder.build());
}
}
Firebase Console Image
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.