List of utility methods to do Package Manage
Drawable | getApplicationIcon(String packageName) get Application Icon if (mContext == null) return null; try { return mContext.getPackageManager().getApplicationIcon( packageName); } catch (NameNotFoundException e) { return null; |
int | getUidForPackageName(PackageManager pm, String packageName) Return the ApplicationInfo#uid for the given package name. try { ApplicationInfo clientInfo = pm.getApplicationInfo(packageName, 0 ); return clientInfo.uid; } catch (NameNotFoundException e) { throw new RuntimeException(e); |
void | disableComponent(PackageManager pm, ComponentName component) disable Component pm.setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); |
void | enableComponent(PackageManager pm, ComponentName component) enable Component pm.setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); |
boolean | isPackageInstalled(String packageName, PackageManager pm) is Package Installed try { String mVersion = pm.getPackageInfo(packageName, 0).versionName; if (mVersion == null) { return false; } catch (NameNotFoundException notFound) { Log.e(TAG, "Package could not be found!", notFound); return false; ... |
Intent | getApplicationMarketPage( @Nonnull String packageName) Returns an Intent with action Intent#ACTION_VIEW to open the Google Play page for the passed package name. return getViewUrlIntent("market://details?id=" + packageName); |
boolean | isPackageInstalled(final String packageName, final PackageManager pm) is Package Installed String mVersion; try { mVersion = pm.getPackageInfo(packageName, 0).versionName; if (mVersion.equals(null)) { return false; } catch (NameNotFoundException e) { return false; ... |
boolean | isSpeechRecognitionActivityPresented( Activity callerActivity) is Speech Recognition Activity Presented try { PackageManager pm = callerActivity.getPackageManager(); List<ResolveInfo> activities = pm .queryIntentActivities(new Intent( RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0); if (activities.size() != 0) { return true; } catch (Exception e) { return false; |
void | uninstall(Context context, String packageName) uninstall Uri uri = Uri.fromParts("package", packageName, null); Intent it = new Intent(Intent.ACTION_DELETE, uri); context.startActivity(it); |
void | uninstallApp(Context context, String packageName) uninstall App Uri packageURI = Uri.parse("package:" + packageName); Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI); context.startActivity(uninstallIntent); |