Identification if the application exists, if not go to the store

a little doozy.

What I would like to know is that if the application does not exist on the device, can it go to the play store to download it. I know that I need to put this code in

Intent i = getPackageManager().getLaunchIntentForPackage("com.package.address"); startActivity(i); 

But if this does not exist, can I get him to go to the Play Store

+8
android
source share
1 answer

You can use one of the following functions to check if the application is installed or not.

Function 1

 private boolean isAppInstalled(String packageName) { PackageManager pm = getPackageManager(); boolean installed = false; try { pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES); installed = true; } catch (PackageManager.NameNotFoundException e) { installed = false; } return installed; } 

Or Function 2

 public boolean isAppInstalled(String targetPackage){ List<ApplicationInfo> packages; PackageManager pm = getPackageManager(); packages = pm.getInstalledApplications(0); for (ApplicationInfo packageInfo : packages) { if(packageInfo.packageName.equals(targetPackage)) return true; } return false; } 

USING

 if(isAppInstalled("com.package.name")){ //Your Code } else{ startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.package.name"))); } 
+9
source share

All Articles