Android Utililty Methods Package Manage

List of utility methods to do Package Manage

Description

The list of methods to do Package Manage are organized into topic(s).

Method

DrawablegetApplicationIcon(String packageName)
get Application Icon
if (mContext == null)
    return null;
try {
    return mContext.getPackageManager().getApplicationIcon(
            packageName);
} catch (NameNotFoundException e) {
    return null;
intgetUidForPackageName(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);
voiddisableComponent(PackageManager pm, ComponentName component)
disable Component
pm.setComponentEnabledSetting(component,
        PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
        PackageManager.DONT_KILL_APP);
voidenableComponent(PackageManager pm, ComponentName component)
enable Component
pm.setComponentEnabledSetting(component,
        PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
        PackageManager.DONT_KILL_APP);
booleanisPackageInstalled(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;
...
IntentgetApplicationMarketPage( @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);
booleanisPackageInstalled(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;
...
booleanisSpeechRecognitionActivityPresented( 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; 
voiduninstall(Context context, String packageName)
uninstall
Uri uri = Uri.fromParts("package", packageName, null);
Intent it = new Intent(Intent.ACTION_DELETE, uri);
context.startActivity(it);
voiduninstallApp(Context context, String packageName)
uninstall App
Uri packageURI = Uri.parse("package:" + packageName);
Intent uninstallIntent = new Intent(Intent.ACTION_DELETE,
        packageURI);
context.startActivity(uninstallIntent);