0

I am a beginner with less idea ,now when i send notifications it always open the launcher activity,i want to open different links as per i set in values.Kindly Elaborate. Thanks

 public class MyFireBaseMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {

   Intent intent = new Intent(this,notifications.class);
    intent.setFlags(intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
    notificationBuilder.setContentTitle("Model Club ");
    notificationBuilder.setContentText(remoteMessage.getNotification().getBody());
    notificationBuilder.setAutoCancel(true);
    notificationBuilder.setContentIntent(pendingIntent);
    notificationBuilder.setSmallIcon(R.drawable.model);

    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, notificationBuilder.build());//*/
}


In android manifest

          <service android:name=".MyFirebaseInstantIdService">
        <intent-filter>
            <action android:name="com.google.firebase.modelclub.firebase.INSTANCE_ID_EVENT" />
        </intent-filter>
    </service>
    <service android:name=".MyFireBaseMessagingService">
        <intent-filter>
            <action android:name="com.example.ankitavishek.modelclub.firebase.MESSAGING_ID_EVENT" />
        </intent-filter>
    </service>
 <activity android:name=".notifications"
        android:label="Notifications"
        android:parentActivityName=".Home">
    <intent-filter>
        <action android:name="com.example.ankitavishek.modelclub_TARGET_NOTIFICATION" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
    </activity>
Ankit Avishek
  • 71
  • 1
  • 1
  • 2

1 Answers1

0

you should also send data like this

{
  "to" : "APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx...",
  "notification" : {
    "body" : "great match!",
    "title" : "Portugal vs. Denmark",
    "icon" : "myicon"
  },
  "data" : {
    "open": "Name of activity"
  }
}

ref: https://firebase.google.com/docs/cloud-messaging/concept-options?hl=es-419

then in

MyFireBaseMessagingService$onMessageReceived

if(remoteMessage.getData().get("open").equals("MY_ACTIVITY")){
    Intent intent = new Intent(this,Activity1.class);
    intent.setFlags(intent.FLAG_ACTIVITY_CLEAR_TOP);
    ...
}
HerberthObregon
  • 1,811
  • 19
  • 23