Search code examples
androidwebviewcrashaurasma

Check if Android app is not installed then prompt a toast message


Solved With This: how to open android application if installed and go to android market if not install

I need to check if an app is installed before start it, and if not prompt the user a toast message like "The app is not installed, please press on the Download from market" or automatically link to market.

My app (main) is a webview with 2 buttons:

  1. Download the app from market (works correctly, html is < a href="inkstudio://market" >)

  2. Launch the app (html is < a href="inkstudio://lancia" >)

If I press the button #1 (download) I can download correctly the app from the PlayStore, and if I press the button #2 the downloaded app start correctly.

But if I press the button#2 when the app is not installed, I get a crash. How can i prevent this?

My code is:

if(url.equals("inkstudio://market")){
    Intent lancia = new Intent(Intent.ACTION_VIEW);
    lancia.setData(Uri.parse("market://details?id=com.aurasma.aurasma"));
    startActivity(lancia);
}
if(url.equals("inkstudio://lancia")){
    Intent lancia = new Intent(Intent.ACTION_VIEW);
    lancia.setData(Uri.parse("aurasma://?YXVyYXNtY"));
    startActivity(lancia);
}

Solution

  • You need to search in the installed applications programmatically in the device. take a look of this:
    How to check programmatically if an application is installed or not in Android?