-4

The code below is used to launch Facebook:

Intent intent = new Intent("android.intent.category.LAUNCHER");
intent.setClassName("com.facebook.katana", "com.facebook.katana.LoginActivity");
startActivity(intent);

I trying to accomplish the same for Yahoo Mail App.

Any idea what names need to be used in the Intent and setClassName statement?

Thanks

Richard
  • 91
  • 1
  • 6
  • 1
    [http://stackoverflow.com/questions/3935009/how-to-open-gmail-compose-when-a-button-is-clicked-in-android-app](http://stackoverflow.com/questions/3935009/how-to-open-gmail-compose-when-a-button-is-clicked-in-android-app) – M D Jun 06 '14 at 04:10

2 Answers2

2

You can use PackageManager.getLaunchIntentForPackage(packageName) to retrieve the Intent associated with launching an app:

PackageManager packageManager = getPackageManager(); // from any Context
Intent intent = packageManager.getLaunchIntentForPackage(
    "com.yahoo.mobile.client.android.mail");

This has the benefit of continuing to work even if they update the application to use a different main activity.

ianhanniballake
  • 191,609
  • 30
  • 470
  • 443
  • This is a good idea. I was just trying to answer the exact question. :) – matiash Jun 06 '14 at 04:46
  • Hannibal,What was your source for looking up the packageName: "com.yahoo.mobile.client.android.mail" – Richard Jun 06 '14 at 17:43
  • @Richard - you can view the package name by looking at the id field in the [Google Play Store URL](https://play.google.com/store/apps/details?id=com.yahoo.mobile.client.android.mail) for the app you want to open. – ianhanniballake Jun 06 '14 at 18:20
1

Try:

intent.setClassName("com.yahoo.mobile.client.android.mail",
    "com.yahoo.mobile.client.android.mail.activity.MainActivity"); 

(The action is always the same).

You can read this information from the APK's manifest.

matiash
  • 54,791
  • 16
  • 125
  • 154