Tuesday, March 29, 2016

How to check if Application is installed in Android Device

We can use below code to check if the Package com.package.name is installed in the Android Device. If not then we can direct the user to google Play Store link for the same.

Intent intent = getPackageManager().getLaunchIntentForPackage("com.package.name");
if (intent != null) {
// We found the activity now start the activity
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
} else {
// Bring user to the market or let them choose an app?
intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(Uri.parse(""https://play.google.com/store/apps/details?id=com.package.name"));
startActivity(intent);

No comments: