2

I want my try to start an intent that uses an another application. But if that application is not installed on that phone i want to show a dialog to inform the user to install the app. I tried the code below:

try {
    startActivity(i);
} catch (Exception e) {
    AlertDialog.Builder b = new AlertDialog.Builder(getApplicationContext());
    b.setMessage("Message Here");
    b.create().show();
}

`

Orhan Obut
  • 8,756
  • 5
  • 32
  • 42
Developer110
  • 182
  • 7

1 Answers1

1

Check installed apps by using this methond

public static boolean isAppInstalled(Context context, String packageName) {
    boolean result;
    try {
        context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
        result = true;
    } catch (PackageManager.NameNotFoundException e) {
        result = false;
    }
    return result;
}
Fedor Kazakov
  • 601
  • 3
  • 12
  • actually that intent opens a video player (like mx player and vlc player)........... so there can be many – Developer110 Jan 20 '15 at 15:57
  • Then you can check all available PackageManager packageManager = getContext().getPackageManager(); List resolveInfos = packageManager.queryIntentActivities(i, 0); – Fedor Kazakov Jan 20 '15 at 15:59