0

I want to create small application which when I start this small application in main activity I want to check if other application for example "barcode" is installed on my phone.

  • If yes I want to start application "barcode"
  • If no I want to install this application from google play.

How I can do that?

Paresh Mayani
  • 122,920
  • 69
  • 234
  • 290
user1302569
  • 6,651
  • 12
  • 44
  • 64

2 Answers2

4

Check with following code if the application is installed

PackageManager pm = getPackageManager();
boolean app_installed = false;
try
{
     pm.getPackageInfo("com.package.Barcode", PackageManager.GET_ACTIVITIES);
     app_installed = true;
}
catch (PackageManager.NameNotFoundException e)
{
     app_installed = false;
}
return app_installed ;

And following code redirects the user to the play store for downloading the application

String appName = "com.package.Barcode";    
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id="+appName));
startActivity(intent);
endian
  • 4,605
  • 7
  • 30
  • 54
2

How to open an existing app you can find here:

Open another application from your own (intent)

And how to check if app exists you can find here:

How can I learn whether a particular package exists on my Android device?

Community
  • 1
  • 1
dilix
  • 3,510
  • 3
  • 27
  • 53