showNotification(notificationMessage, customAction);
kullanarak üsttende gösterebiliriz
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
String notificationMessage = remoteMessage.getNotification().getBody();
String customAction = remoteMessage.getData().get("customAction");
showNotification(notificationMessage, customAction);
}
private void showNotification(String message, String customAction) {
Intent intent = new Intent(this, YourTargetActivity.class);
intent.putExtra("notificationData", message);
intent.putExtra("customAction", customAction);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, CHANNEL_ID)
.setContentTitle("Başlık")
.setContentText(message)
.setSmallIcon(R.drawable.ic_notification)
.setContentIntent(pendingIntent);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(notificationId, notificationBuilder.build());
}bundan sonra onCreate veya onNewIntent kullanmamız gerek
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_your_target);
if (getIntent() != null && getIntent().hasExtra("notificationData") && getIntent().hasExtra("customAction")) {
String notificationMessage = getIntent().getStringExtra("notificationData");
String customAction = getIntent().getStringExtra("customAction");
if ("goToFragmentA".equals(customAction)) {
navigateToFragmentA(notificationMessage);
} else if ("goToFragmentB".equals(customAction)) {
navigateToFragmentB(notificationMessage);
}
}
}
private void navigateToFragmentA(String message) {
FragmentA fragmentA = new FragmentA();
}
private void navigateToFragmentB(String message) {
FragmentB fragmentB = new FragmentB();
}