How to open an activity when a push arrives in Backgroud

0

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());
    }
}
    
asked by Elihat Caceres 14.01.2017 в 18:00
source

1 answer

-1

I found an example I hope you find useful, use the notication.flag Notification solution

    
answered by 19.01.2017 в 15:45