I want to consult, how to make the Notifications.class activity open when a push message arrives with the background application.
I have a main.class that is my main main and launcher in the manifest. and a notifications.class that opens for notifications.
* When the application is in Foreground and the push message arrives, when you click on the push it automatically goes from main.class to notifications.class and is just what I want .
* But when the application is in Background and the push message arrives, when you click on the push it goes to the main.class (as I do so instead of the main. class go to notifications.class)
Thanks in advance ... Here is the code of the firebaseservice:
public class MiFirebaseMessaginService extends FirebaseMessagingService {
public static final String TAG ="NOTICIAS";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
String from = remoteMessage.getFrom();
Log.d(TAG, "Mensaje recibido de:" + from);
if (remoteMessage.getNotification() !=null){
Log.d(TAG, "Notificacion:" + remoteMessage.getNotification().getBody());
mostrarNotificacion(remoteMessage.getNotification().getTitle(),remoteMessage.getNotification().getBody());
}
if (remoteMessage.getData().size()> 0){
Log.d(TAG, "Data:" + remoteMessage.getData());
}
}
private void mostrarNotificacion(String title, String body) {
Intent intent = new Intent(this, Notificaciones.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder= (NotificationCompat.Builder) new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_notifications_active_black_24dp)
.setContentTitle(title)
.setContentText(body)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setVisibility(android.support.v4.app.NotificationCompat.VISIBILITY_PUBLIC)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}
}