How to check programmatically if an application is installed or not in Android?
Try with this:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Add respective layout
setContentView(R.layout.main_activity);
// Use package name which we want to check
boolean isAppInstalled = appInstalledOrNot("com.check.application");
if(isAppInstalled) {
//This intent will help you to launch if the package is already installed
Intent LaunchIntent = getPackageManager()
.getLaunchIntentForPackage("com.check.application");
startActivity(LaunchIntent);
Log.i("SampleLog", "Application is already installed.");
} else {
// Do whatever we want to do if application not installed
// For example, Redirect to play store
Log.i("SampleLog", "Application is not currently installed.");
}
}
private boolean appInstalledOrNot(String uri) {
PackageManager pm = getPackageManager();
try {
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
return true;
} catch (PackageManager.NameNotFoundException e) {
}
return false;
}
}
How to know if a particular application is installed or not on the device?
I found the answer here
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> pkgAppsList =
context.getPackageManager().queryIntentActivities( mainIntent, 0);
for (ResolveInfo resolveInfo : pkgAppsList) {
Log.d(TAG, "__<>"+resolveInfo.activityInfo.packageName);
if (resolveInfo.activityInfo.packageName != null
&& resolveInfo.activityInfo.packageName.equals(uri)) {
return true;
}
}
return false;
This worked for me perfectly.
Check if application is installed - Android
Try this:
private boolean isPackageInstalled(String packageName, PackageManager packageManager) {
try {
packageManager.getPackageInfo(packageName, 0);
return true;
} catch (PackageManager.NameNotFoundException e) {
return false;
}
}
It attempts to fetch information about the package whose name you passed in. Failing that, if a NameNotFoundException
was thrown, it means that no package with that name is installed, so we return false
.
Note that we pass in a PackageManager
instead of a Context
, so that the method is slightly more flexibly usable and doesn't violate the law of Demeter. You can use the method without access to a Context
instance, as long as you have a PackageManager
instance.
Use it like this:
public void someMethod() {
// ...
PackageManager pm = context.getPackageManager();
boolean isInstalled = isPackageInstalled("com.somepackage.name", pm);
// ...
}
Note: From Android 11 (API 30), you might need to declare <queries>
in your manifest, depending on what package you're looking for. Check out the docs for more info.
How can I check whether an app is installed and open it?
Use this method.
public void OpenApp() {
PackageManager pm = getPackageManager();
final String LiveAppPackage = "com.example.app"; //Change to your package name.
try {
pm.getPackageInfo(LiveAppPackage, PackageManager.GET_ACTIVITIES);
Intent intent = pm.getLaunchIntentForPackage(LiveAppPackage);
if (intent == null) {
throw new PackageManager.NameNotFoundException();
}
intent.addCategory(Intent.CATEGORY_LAUNCHER);
context.startActivity(intent);
}
catch (PackageManager.NameNotFoundException e) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
ActivityThis);
DialogInterface.OnClickListener onClickListener = new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
if(which == DialogInterface.BUTTON_POSITIVE){
//Try to open Market and if fails, open play store.
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri
.parse("market://details?id="
+ LiveAppPackage)));
} catch (android.content.ActivityNotFoundException e1) {
startActivity(new Intent(
Intent.ACTION_VIEW,
Uri.parse("https://play.google.com/store/apps/details?id="
+ LiveAppPackage)));
}
} else{
dialog.dismiss();
}
}
};
alertDialogBuilder.setTitle("App Title")
.setCancelable(true)
.setPositiveButton("Install", onClickListener);
alertDialogBuilder.setNegativeButton("Cancel", onClickListener);
alertDialogBuilder.setMessage("Second app is not currently installed\n\nLike to install it?"); //Change to your message
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
}
}
Check App is installed on device android code
try this code :
protected boolean isAppInstalled(String packageName) {
Intent mIntent = getPackageManager().getLaunchIntentForPackage(packageName);
if (mIntent != null) {
return true;
}
else {
return false;
}
}
to get the package name of the app easily : just search your app in the google play website
, and then you will take the id parameter ( it is the package name of the app) . Example :
you will search on Youtube app on google play , and you will find it in this url :
https://play.google.com/store/apps/details?id=com.google.android.youtube&feature=search_result#?t=W251bGwsMSwxLDEsImNvbS5nb29nbGUuYW5kcm9pZC55b3V0dWJlIl0.
the package name is the id param, so it is : com.google.android.youtube
And then when you want to test , you will just have :
String packageName = "com.google.android.youtube";
boolean isYoutubeInstalled = isAppInstalled(packageName);
PLUS : if you want to get the list of all installed apps in you device , you can find your answer in this tutorial
How to check programmatically if an App is installed?
I think this is not possible directly, but if the apps register uri schemes you could test for that.
A URI scheme is for example fb://
for the facebook app. You can register that in the info.plist of your app. [UIApplication canOpenURL:url]
will tell you if a certain url will or will not open. So testing if fb://
will open, will indicate that there is an app installed which registered fb://
- which is a good hint for the facebook app.
// check whether facebook is (likely to be) installed or not
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"fb://"]]) {
// Safe to launch the facebook app
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"fb://profile/200538917420"]];
}
Related Topics
Adb.Exe Not Found After Installing Android Studio
How to Delete or Remove Cardview from Recyclerview - Android Studio
How to Remove Focus from Edittext When User Is Done Editing
Images Are Not Visible in React-Native App Release Build
How to Change Background Color of Layout of List-View Item Using Array-Adapter
How to Restrict Entry of Numbers But Allow All the Special Characters and Alphabets in Edittext
How to Change the Background Color of the Options Menu
How to Set the Preview Image in Videoview Before Playing
Html File Input Control With Capture and Accept Attributes Works Wrong
Allow User to Select Camera or Gallery For Image
Play Store Alpha Test Download Link Not Working
How to Make a New Line or Tab in <String> Xml (Eclipse/Android)
Android No on Screen Keybord ( Only Voice )
Android Studio: Emulator Is Running But Not Showing Up in Run App "Choose a Running Device"
How to Show the Number Keyboard on an Edittext in Android
How to Create a Video from an Array of Images in Android
Failure Install Parse Failed Manifest Malformed
Adb Error (Error: Protocol Fault (Couldn't Read Status): Invalid Argument)