0

I have been trying out how to make a notification for my app open up a different application such as inbox. I have only seen how to open a specific activity and don't know if it is possible to open an entire application.

Sunil Sharma
  • 2,653
  • 1
  • 25
  • 36
BestCharlemagne
  • 91
  • 2
  • 10
  • I think it is possible.. You just need to configure the intent properly... But I never tried.. so, I can't confirm – guipivoto Jul 20 '16 at 20:58
  • There is no "entire application" in Android. That is akin to asking how to link to an "entire Web site" from your Web page. You can start a launcher activity for the application, given that you know its application ID ("package name") to use with `PackageManager`. Since not everybody uses Google Inbox, you would need some way to allow users to decide what application you should open. – CommonsWare Jul 20 '16 at 21:04

2 Answers2

1

Yes. It is possible. You just need to configure your intent properly.

CAUTION

End user may not have installed the app that you want.. So, you have to implement methods to control that...

But anyway, it is possible to open a different app from your own notification

Example

I created example below for whatsapp. I used this question as reference.

Notification.Builder notiBuilder = new Notification.Builder(this);
Intent intent = null;

/*
    START
    Configure your intent here.
    Example below opens the whatspp.. I got this example from https://stackoverflow.com/questions/15462874/sending-message-through-whatsapp/15931345#15931345
    You must update it to open the app that you want.

    If the app is not found, intent is null and then, click in notification won't do anything
*/
PackageManager pm=getPackageManager();
try {
    PackageInfo info = pm.getPackageInfo("com.whatsapp", PackageManager.GET_META_DATA);
    intent = new Intent(Intent.ACTION_SEND);
    intent.setPackage("com.whatsapp");
    intent.setType("text/plain");
} catch (PackageManager.NameNotFoundException e) {
    // Package not found
    intent = null;
    e.printStackTrace();
}
/*  END  */

if(intent != null) {
    PendingIntent clickPendingIntent = PendingIntent.getActivity(
            this,
            0,
            intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    notiBuilder.setContentTitle("Title")
            .setSmallIcon(R.drawable.common_google_signin_btn_icon_light)
            .setContentText("Message")
            .setContentIntent(clickPendingIntent)
            .setLights(Color.BLUE, 3000, 3000);
} else {
    notiBuilder.setContentTitle("Title")
            .setSmallIcon(R.drawable.common_google_signin_btn_icon_light)
            .setContentText("Message")
            .setLights(Color.BLUE, 3000, 3000);
}

Notification mNotificationBar = notiBuilder.build();
mNotificationBar.flags |= Notification.DEFAULT_SOUND;
mNotificationBar.flags |= Notification.FLAG_SHOW_LIGHTS;
mNotificationBar.flags |= Notification.FLAG_AUTO_CANCEL;

NotificationManager mNotificationManager = (NotificationManager) this.getSystemService(Service.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, mNotificationBar);

Open Dialer

Just configure the intent like below:

intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:0123456789"));
Community
  • 1
  • 1
guipivoto
  • 18,327
  • 9
  • 60
  • 75
0

Here is the official docs on how to create an implicit intent.

https://developer.android.com/training/basics/intents/sending.html

Is this what you meant?

Narine Cholakian
  • 189
  • 1
  • 2
  • 13