How can I find if a particular package exists on my Android device?
Call any of the below method with the package name.
import android.content.pm.PackageManager;
// ...
public boolean isPackageExisted(String targetPackage){
List<ApplicationInfo> packages;
PackageManager pm;
pm = getPackageManager();
packages = pm.getInstalledApplications(0);
for (ApplicationInfo packageInfo : packages) {
if(packageInfo.packageName.equals(targetPackage))
return true;
}
return false;
}
import android.content.pm.PackageManager;
public boolean isPackageExisted(String targetPackage){
PackageManager pm=getPackageManager();
try {
PackageInfo info=pm.getPackageInfo(targetPackage,PackageManager.GET_META_DATA);
} catch (PackageManager.NameNotFoundException e) {
return false;
}
return true;
}
Check if a package is installed in Android
Try this
PackageManager pm = getPackageManager();
boolean app_installed;
try {
pm.getPackageInfo("PackageName",PackageManager.GET_ACTIVITIES);
app_installed = true;
}
catch (PackageManager.NameNotFoundException e) {
app_installed = false;
}
And see this
Check if a package exists on Android Market
You can perform a simple test on the Android market URL as
https://play.google.com/store/apps/details?id=
com.mycompany.myapp
Pass your Application Package name with the letters indented in bold letters in above URL, if you get any result then it is concluded that the Application Package name is already been used, if you get "We're sorry, the requested URL was not found on this server." then you can use the app package name.
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 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.
Android: How to Know if any application is already installed in android device using adb?
[Update 2]
Without using grep
adb shell pm list packages [your.package.name]
as mentioned in the below answer
[Update]
According to (also) correct answer below, try grep the result from pm list packages.
adb shell pm list packages | grep com.your.app.package
[Original]
If the application is already installed and if you try to install the same app again, adb will return with an error - Failure [INSTALL_FAILED_ALREADY_EXISTS]
. However, if you want to re-install the already installed app, then use -r
parameter.
Ex:
adb install -r game.apk
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;
}
}
Related Topics
Mediacodec and Camera: Colorspaces Don't Match
Why Is Android Studio Reporting "Uri Is Not Registered"
Adb Root Is Not Working on Emulator (Cannot Run as Root in Production Builds)
How to Pause/Resume Thread in Android
Match_Parent Width Does Not Work in Recyclerview
Why Are Most UI Frameworks Single Threaded
Android - Get Children Inside a View
How to Get the Md5 Fingerprint from Java's Keytool, Not Only Sha-1
How to Downgrade My Sdk Version
Sending Text Messages Programmatically in Android
Enable/Disable Zoom in Android Webview
Get the Current Fragment Object
Using Android Vector Drawables on Pre Lollipop Crash