0

Quiero consultar, como hacer que se abra la activity notificaciones.class cuando llegue un mensaje push con la aplicacion en background.

tengo una main.class que es mi main principal y launcher en el manifest. y una notificaciones.class que se abre para las notificaciones.

*Cuando la aplicacion esta en Foreground y llega el mensaje push, al dar click en el push pasa automaticamente de main.class hacia notificaciones.class y es justo lo que quiero.

*Pero cuando la aplicacion esta en Background y llega el mensaje push, al dar click en el push se va hacia el main.class (como hago para que en vez del main.class vaya hacia notificaciones.class)

Gracias de antemano... Aqui les dejo el codigo del 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());
    }
}

1 respuesta 1

-1

He encontrado un ejemplo espero que te sirve de utilidad, usa el notication.flag Notificación solución

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.