Open activity from notification created by second application

2

I have two applications on android one of which generates a notification in the notification bar when an X event occurs, it could be a query to a database, when connecting the device to the current, etc.

I would like to know if there is a way to open the second application when selecting the notification generated by the first application.

I do not have any type of code but if one idea is that it could be carried out with a BroadcastReceiver, if I do not find it or rather I can not think of how to do it.

Can it be done?

    
asked by Cesar 30.08.2016 в 21:33
source

1 answer

3

Cesar, you should simply define a PendingIntent but instead of opening an Activity in your application , you will open one in another application

Intent notificationIntent = new Intent().setClassName("com.otraaplicacion", "com.otraaplicacion.Activity")

Review this answer: link

It would be like this:

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ctx)
                .setSmallIcon(R.drawable.ic_launcher)
                .setContentTitle(ctx.getResources().getString(R.string.app_name))
                .setContentText("mi mensaje")
                .setWhen(System.currentTimeMillis());

    //Intent notificacionIntent =  new Intent(ctx.getApplicationContext(), MainActivity.class);
 // Abre Activity de otra aplicación.
    Intent notificationIntent = new Intent().setClassName("com.otraaplicacion", "com.otraaplicacion.Activity")

                //Puedes definir valores extras para agregar en el Bundle del Intent.
                /*extras.putInt("seccion", 1);
                extras.putString("mensaje", "Este es mi mensaje");
                extras.putBoolean("esWidget", true);
                notIntent.putExtras(extras);*/
                PendingIntent pendingIntent = PendingIntent.getActivity(ctx, 1, notificacionIntent, FLAG_NONE);
                mBuilder.setContentIntent(pendingIntent);
                mBuilder.setAutoCancel(true);
    
answered by 31.08.2016 / 01:42
source