Example usage for android.content.pm ApplicationInfo loadIcon

List of usage examples for android.content.pm ApplicationInfo loadIcon

Introduction

In this page you can find the example usage for android.content.pm ApplicationInfo loadIcon.

Prototype

public Drawable loadIcon(PackageManager pm) 

Source Link

Document

Retrieve the current graphical icon associated with this item.

Usage

From source file:com.harshad.linconnectclient.ApplicationSettingsActivity.java

private void setupSimplePreferencesScreen() {
    addPreferencesFromResource(R.xml.pref_application);

    applicationCategory = (PreferenceCategory) findPreference("header_application");

    // Listen for check/uncheck all tap
    findPreference("pref_all").setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        @Override/*  ww w .j a  v a2s.  co m*/
        public boolean onPreferenceChange(Preference arg0, Object arg1) {
            for (int i = 0; i < applicationCategory.getPreferenceCount(); i++) {
                // Uncheck or check all items
                ((CheckBoxPreference) (applicationCategory.getPreference(i))).setChecked((Boolean) arg1);
            }
            return true;
        }
    });

    class ApplicationTask extends AsyncTask<String, Void, List<ApplicationInfo>> {
        private PackageManager packageManager;

        @Override
        protected void onPreExecute() {
            progressDialog = ProgressDialog.show(ApplicationSettingsActivity.this, null, "Loading...", true);
        }

        @Override
        protected List<ApplicationInfo> doInBackground(String... notif) {

            packageManager = getApplicationContext().getPackageManager();

            // Comparator used to sort applications by name
            class CustomComparator implements Comparator<ApplicationInfo> {
                @Override
                public int compare(ApplicationInfo arg0, ApplicationInfo arg1) {
                    return arg0.loadLabel(packageManager).toString()
                            .compareTo(arg1.loadLabel(packageManager).toString());
                }
            }

            // Get installed applications
            Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
            mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
            List<ApplicationInfo> appList = getApplicationContext().getPackageManager()
                    .getInstalledApplications(PackageManager.GET_META_DATA);

            // Sort by application name
            Collections.sort(appList, new CustomComparator());

            return appList;
        }

        @Override
        protected void onPostExecute(List<ApplicationInfo> result) {
            // Add each application to screen
            for (ApplicationInfo appInfo : result) {
                CheckBoxPreference c = new CheckBoxPreference(ApplicationSettingsActivity.this);
                c.setTitle(appInfo.loadLabel(packageManager).toString());
                c.setSummary(appInfo.packageName);
                c.setIcon(appInfo.loadIcon(packageManager));
                c.setKey(appInfo.packageName);
                c.setChecked(true);

                c.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
                    @Override
                    public boolean onPreferenceChange(Preference arg0, Object arg1) {
                        // On tap, show an enabled/disabled notification on the desktop
                        Object[] notif = new Object[3];

                        if (arg1.toString().equals("true")) {
                            notif[0] = arg0.getTitle().toString() + " notifications enabled";
                            notif[1] = "via LinConnect";
                            notif[2] = arg0.getIcon();
                        } else {
                            notif[0] = arg0.getTitle().toString() + " notifications disabled";
                            notif[1] = "via LinConnect";
                            notif[2] = arg0.getIcon();
                        }

                        new TestTask().execute(notif);

                        return true;
                    }

                });

                applicationCategory.addPreference(c);
            }
            progressDialog.dismiss();
        }
    }

    new ApplicationTask().execute();

}

From source file:com.tundem.aboutlibraries.ui.LibsFragment.java

private void generateAboutThisAppSection() {
    if (aboutShowIcon != null && aboutShowVersion != null) {
        View headerView = getActivity().getLayoutInflater().inflate(R.layout.listheader_opensource, null);

        //get the about this app views
        ImageView aboutIcon = (ImageView) headerView.findViewById(R.id.aboutIcon);
        TextView aboutVersion = (TextView) headerView.findViewById(R.id.aboutVersion);
        View aboutDivider = headerView.findViewById(R.id.aboutDivider);
        TextView aboutAppDescription = (TextView) headerView.findViewById(R.id.aboutDescription);

        //get the packageManager to load and read some values :D
        PackageManager pm = getActivity().getPackageManager();
        //get the packageName
        String packageName = getActivity().getPackageName();
        //Try to load the applicationInfo
        ApplicationInfo appInfo = null;
        PackageInfo packageInfo = null;/*from  w  w  w .j av  a 2 s . c  om*/
        try {
            appInfo = pm.getApplicationInfo(packageName, 0);
            packageInfo = pm.getPackageInfo(packageName, 0);
        } catch (Exception ex) {
        }

        //Set the Icon or hide it
        if (aboutShowIcon && appInfo != null) {
            aboutIcon.setImageDrawable(appInfo.loadIcon(pm));
        } else {
            aboutIcon.setVisibility(View.GONE);
        }

        //set the Version or hide it
        if (aboutShowVersion && packageInfo != null) {
            String versionName = packageInfo.versionName;
            int versionCode = packageInfo.versionCode;
            aboutVersion.setText(getString(R.string.version) + " " + versionName + " (" + versionCode + ")");
        } else {
            aboutVersion.setVisibility(View.GONE);
        }

        //Set the description or hide it
        if (!TextUtils.isEmpty(aboutDescription)) {
            aboutAppDescription.setText(aboutDescription);
        } else {
            aboutAppDescription.setVisibility(View.GONE);
        }

        //if there is no description or no icon and version number hide the divider
        if (!aboutShowIcon && !aboutShowVersion || TextUtils.isEmpty(aboutDescription)) {
            aboutDivider.setVisibility(View.GONE);
        }

        //add this cool thing to the headerView of our listView
        listView.addHeaderView(headerView, null, false);
    }
}

From source file:com.kuloud.android.aboutlibraries.ui.LibsFragment.java

private void generateAboutThisAppSection() {
    if (aboutShowIcon != null
            && (aboutShowVersion != null || aboutShowVersionName != null || aboutShowVersionCode)) {
        //get the packageManager to load and read some values :D
        PackageManager pm = getActivity().getPackageManager();
        //get the packageName
        String packageName = getActivity().getPackageName();
        //Try to load the applicationInfo
        ApplicationInfo appInfo = null;
        PackageInfo packageInfo = null;/* www  .  j  a v a2s .  c om*/
        try {
            appInfo = pm.getApplicationInfo(packageName, 0);
            packageInfo = pm.getPackageInfo(packageName, 0);
        } catch (Exception ex) {
        }

        //Set the Icon or hide it
        Drawable icon = null;
        if (aboutShowIcon && appInfo != null) {
            icon = appInfo.loadIcon(pm);
        }

        //set the Version or hide it
        String versionName = null;
        Integer versionCode = null;
        if (packageInfo != null) {
            versionName = packageInfo.versionName;
            versionCode = packageInfo.versionCode;
        }

        //add this cool thing to the headerView of our listView
        mAdapter.setHeader(aboutAppName, aboutDescription, aboutSpecial1, aboutSpecial1Description,
                aboutSpecial2, aboutSpecial2Description, aboutSpecial3, aboutSpecial3Description, versionName,
                versionCode, aboutShowVersion, aboutShowVersionName, aboutShowVersionCode, icon, aboutShowIcon);
    }
}

From source file:com.rp.podemu.SettingsActivity.java

private void setCtrlApplicationInfo() {
    String processName = sharedPref.getString("ControlledAppProcessName", "unknown application");

    PackageManager pm = getPackageManager();
    ApplicationInfo appInfo;
    TextView textView = (TextView) findViewById(R.id.ctrlAppName);

    try {/* w  w w.  jav  a 2s.  c om*/
        appInfo = pm.getApplicationInfo(processName, PackageManager.GET_META_DATA);

        textView.setText(appInfo.loadLabel(pm));

        ImageView imageView = (ImageView) findViewById(R.id.ctrlAppIcon);
        imageView.setImageDrawable(appInfo.loadIcon(pm));

    } catch (PackageManager.NameNotFoundException e) {
        textView.setText("Cannot load application ");
    }

}

From source file:com.aware.ui.Plugins_Manager.java

private void drawUI() {
    //Clear previous states
    store_grid.removeAllViews();//from   w  ww. j a v  a2s . c  o m

    //Build UI
    Cursor installed_plugins = getContentResolver().query(Aware_Plugins.CONTENT_URI, null, null, null,
            Aware_Plugins.PLUGIN_NAME + " ASC");
    if (installed_plugins != null && installed_plugins.moveToFirst()) {
        do {
            final String package_name = installed_plugins
                    .getString(installed_plugins.getColumnIndex(Aware_Plugins.PLUGIN_PACKAGE_NAME));
            final String name = installed_plugins
                    .getString(installed_plugins.getColumnIndex(Aware_Plugins.PLUGIN_NAME));
            final String description = installed_plugins
                    .getString(installed_plugins.getColumnIndex(Aware_Plugins.PLUGIN_DESCRIPTION));
            final String developer = installed_plugins
                    .getString(installed_plugins.getColumnIndex(Aware_Plugins.PLUGIN_AUTHOR));
            final String version = installed_plugins
                    .getString(installed_plugins.getColumnIndex(Aware_Plugins.PLUGIN_VERSION));
            final int status = installed_plugins
                    .getInt(installed_plugins.getColumnIndex(Aware_Plugins.PLUGIN_STATUS));

            final View pkg_view = inflater.inflate(R.layout.plugins_store_pkg_list_item, null, false);
            pkg_view.setTag(package_name); //each view has the package name as a tag for easier references

            try {
                ImageView pkg_icon = (ImageView) pkg_view.findViewById(R.id.pkg_icon);
                if (status != PLUGIN_NOT_INSTALLED) {
                    ApplicationInfo appInfo = getPackageManager().getApplicationInfo(package_name,
                            PackageManager.GET_META_DATA);
                    pkg_icon.setImageDrawable(appInfo.loadIcon(getPackageManager()));
                } else {
                    byte[] img = installed_plugins
                            .getBlob(installed_plugins.getColumnIndex(Aware_Plugins.PLUGIN_ICON));
                    if (img != null)
                        pkg_icon.setImageBitmap(BitmapFactory.decodeByteArray(img, 0, img.length));
                }

                TextView pkg_title = (TextView) pkg_view.findViewById(R.id.pkg_title);
                pkg_title.setText(installed_plugins
                        .getString(installed_plugins.getColumnIndex(Aware_Plugins.PLUGIN_NAME)));

                ImageView pkg_state = (ImageView) pkg_view.findViewById(R.id.pkg_state);

                switch (status) {
                case PLUGIN_DISABLED:
                    pkg_state.setVisibility(View.INVISIBLE);
                    pkg_view.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            AlertDialog.Builder builder = getPluginInfoDialog(name, version, description,
                                    developer);
                            if (isClassAvailable(package_name, "Settings")) {
                                builder.setNegativeButton("Settings", new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        dialog.dismiss();
                                        Intent open_settings = new Intent();
                                        open_settings.setClassName(package_name, package_name + ".Settings");
                                        startActivity(open_settings);
                                    }
                                });
                            }
                            builder.setPositiveButton("Activate", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                    Aware.startPlugin(getApplicationContext(), package_name);
                                    drawUI();
                                }
                            });
                            builder.create().show();
                        }
                    });
                    break;
                case PLUGIN_ACTIVE:
                    pkg_state.setImageResource(R.drawable.ic_pkg_active);
                    pkg_view.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            AlertDialog.Builder builder = getPluginInfoDialog(name, version, description,
                                    developer);
                            if (isClassAvailable(package_name, "Settings")) {
                                builder.setNegativeButton("Settings", new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        dialog.dismiss();
                                        Intent open_settings = new Intent();
                                        open_settings.setClassName(package_name, package_name + ".Settings");
                                        startActivity(open_settings);
                                    }
                                });
                            }
                            builder.setPositiveButton("Deactivate", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                    Aware.stopPlugin(getApplicationContext(), package_name);
                                    drawUI();
                                }
                            });
                            builder.create().show();
                        }
                    });
                    break;
                case PLUGIN_UPDATED:
                    pkg_state.setImageResource(R.drawable.ic_pkg_updated);
                    pkg_view.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            AlertDialog.Builder builder = getPluginInfoDialog(name, version, description,
                                    developer);
                            if (isClassAvailable(package_name, "Settings")) {
                                builder.setNegativeButton("Settings", new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        dialog.dismiss();
                                        Intent open_settings = new Intent();
                                        open_settings.setClassName(package_name, package_name + ".Settings");
                                        startActivity(open_settings);
                                    }
                                });
                            }
                            builder.setNeutralButton("Deactivate", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                    Aware.stopPlugin(getApplicationContext(), package_name);
                                    drawUI();
                                }
                            });
                            builder.setPositiveButton("Update", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                    Aware.downloadPlugin(getApplicationContext(), package_name, true);
                                }
                            });
                            builder.create().show();
                        }
                    });
                    break;
                case PLUGIN_NOT_INSTALLED:
                    pkg_state.setImageResource(R.drawable.ic_pkg_download);
                    pkg_view.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            AlertDialog.Builder builder = getPluginInfoDialog(name, version, description,
                                    developer);
                            builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                }
                            });
                            builder.setPositiveButton("Install", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                    Aware.downloadPlugin(getApplicationContext(), package_name, false);
                                }
                            });
                            builder.create().show();
                        }
                    });
                    break;
                }
                store_grid.addView(pkg_view);
            } catch (NameNotFoundException e) {
                e.printStackTrace();
            }
        } while (installed_plugins.moveToNext());
    }
    if (installed_plugins != null && !installed_plugins.isClosed())
        installed_plugins.close();
}

From source file:com.android.leanlauncher.IconCache.java

/**
 * Gets an entry for the package, which can be used as a fallback entry for various components.
 * This method is not thread safe, it must be called from a synchronized method.
 *///from  w ww  .j av a 2s.  c om
private CacheEntry getEntryForPackage(String packageName, UserHandleCompat user) {
    ComponentName cn = new ComponentName(packageName, EMPTY_CLASS_NAME);
    CacheKey cacheKey = new CacheKey(cn, user);
    CacheEntry entry = mCache.get(cacheKey);
    if (entry == null || entry.icon == null) {
        entry = new CacheEntry();

        try {
            ApplicationInfo info = mPackageManager.getApplicationInfo(packageName, 0);
            entry.title = info.loadLabel(mPackageManager);
            entry.contentDescription = info.loadDescription(mPackageManager);
            Drawable defaultDrawable = info.loadIcon(mPackageManager);
            if (!TextUtils.isEmpty(mCurrentIconTheme)) {
                entry.icon = createNewIconBitmap(null, packageName, null, defaultDrawable);
            }

            if (entry.icon == null) {
                // pick default icon
                Log.d(TAG, packageName + " icon NOT FOUND in theme = " + mCurrentIconTheme);
                entry.icon = Utilities.createIconBitmap(defaultDrawable, mContext);
            }
            mCache.put(cacheKey, entry);
        } catch (NameNotFoundException e) {
            if (DEBUG)
                Log.d(TAG, "Application not installed " + packageName);
        }
    }
    return entry;
}

From source file:com.spydiko.rotationmanager.MainActivity.java

public void updateApps() {
    //      if(AppSpecificOrientation.LOG) Log.d(TAG, "0");
    Intent localIntent = new Intent("android.intent.action.MAIN", null);
    localIntent.addCategory("android.intent.category.LAUNCHER");
    //      if(AppSpecificOrientation.LOG) Log.d(TAG, "1");
    packageManager = getPackageManager();
    //      if(AppSpecificOrientation.LOG) Log.d(TAG, "2");
    List<ResolveInfo> rInfo = packageManager.queryIntentActivities(localIntent, 1);
    //      if(AppSpecificOrientation.LOG) Log.d(TAG, "3");
    List<ApplicationInfo> packages = new ArrayList<ApplicationInfo>();
    //      if(AppSpecificOrientation.LOG) Log.d(TAG, "4");
    for (ResolveInfo info : rInfo) {
        packages.add(info.activityInfo.applicationInfo);
    }//from w w  w .ja v  a 2  s  . co  m
    Model temp;
    for (ApplicationInfo packageInfo : packages) {
        //         if(AppSpecificOrientation.LOG) Log.d(TAG, "Installed package :" + packageInfo.packageName);
        if (names.contains(packageInfo.packageName)) {
            continue;
        }
        names.add(packageInfo.packageName);
        temp = new Model((String) packageManager.getApplicationLabel(packageInfo));
        temp.setPackageName(packageInfo.packageName);
        Drawable pic = packageInfo.loadIcon(packageManager);
        temp.setLabel(pic);
        //         if(AppSpecificOrientation.LOG) Log.d(TAG, "Installed package :" + temp.getName());
        //temp.put(IS_CHECKED, true);
        if (myapp.loadPreferences(packageInfo.packageName, true))
            temp.setSelectedPortrait(true);
        if (myapp.loadPreferences(packageInfo.packageName, false))
            temp.setSelectedLandscape(true);
        activities.add(temp);

        //         if(AppSpecificOrientation.LOG) Log.d(TAG, "Launch Activity :" + packageManager.getLaunchIntentForPackage(packageInfo.packageName));
    }
    // Search and show launchers
    final Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    final ResolveInfo res = packageManager.resolveActivity(intent, 0);
    if (res.activityInfo == null) {
        // should not happen. A home is always installed, isn't it?
    } else if (!names.contains(res.activityInfo.applicationInfo.packageName)) {
        names.add(res.activityInfo.applicationInfo.packageName);
        Model launcher = new Model(
                (String) packageManager.getApplicationLabel(res.activityInfo.applicationInfo));
        launcher.setPackageName(res.activityInfo.applicationInfo.packageName);
        Drawable launcher_pic = res.activityInfo.applicationInfo.loadIcon(packageManager);
        launcher.setLabel(launcher_pic);
        if (myapp.loadPreferences(res.activityInfo.applicationInfo.packageName, true))
            launcher.setSelectedPortrait(true);
        if (myapp.loadPreferences(res.activityInfo.applicationInfo.packageName, false))
            launcher.setSelectedLandscape(true);
        activities.add(launcher);
    }
    if (!names.contains("com.android.phone")) {
        names.add("com.android.phone");
        Model phone = new Model("Phone During Call");
        phone.setPackageName("com.android.phone");
        Drawable ic_phone = getResources().getDrawable(R.drawable.ic_phone);
        phone.setLabel(ic_phone);
        if (myapp.loadPreferences("com.android.phone", true))
            phone.setSelectedPortrait(true);
        if (myapp.loadPreferences("com.android.phone", false))
            phone.setSelectedLandscape(true);
        activities.add(phone);
    }

    Collections.sort(activities, new SortByString());

    Collections.sort(activities, new SortByCheck());

    //      if(AppSpecificOrientation.LOG) Log.d(TAG, "END");
}

From source file:com.rp.podemu.MainActivity.java

private void loadPreferences() {
    try {//  www  . jav  a 2s  .  c o  m
        ImageView appLogo = (ImageView) findViewById(R.id.CTRL_app_icon);
        SharedPreferences sharedPref = this.getSharedPreferences("PODEMU_PREFS", Context.MODE_PRIVATE);
        ctrlAppProcessName = sharedPref.getString("ControlledAppProcessName", "unknown app");
        String enableDebug = sharedPref.getString("enableDebug", "false");
        Boolean ctrlAppUpdated = sharedPref.getBoolean("ControlledAppUpdated", false);

        if (PodEmuMediaStore.getInstance() == null) {
            PodEmuMediaStore.initialize(this);
        }

        // update ctrlApp only if it was changed or MediaPlayback engine is not yet initialized
        if (ctrlAppUpdated || MediaPlayback.getInstance() == null) {
            PodEmuMediaStore.getInstance().setCtrlAppProcessName(ctrlAppProcessName);
        }

        if (enableDebug.equals("true"))
            PodEmuLog.DEBUG_LEVEL = 2;
        else
            PodEmuLog.DEBUG_LEVEL = 0;

        if (podEmuService != null) {
            podEmuService.reloadBaudRate();
        }

        if (MediaPlayback.getInstance() != null) {
            currentlyPlaying.bulk_update(
                    MediaPlayback.getInstance().getCurrentPlaylist().getCurrentTrack().toPodEmuMessage());
            updateCurrentlyPlayingDisplay();
        }

        PackageManager pm = getPackageManager();
        ApplicationInfo appInfo;

        try {
            appInfo = pm.getApplicationInfo(ctrlAppProcessName, PackageManager.GET_META_DATA);

            ctrlAppStatusTitle.setText("Controlled app: " + appInfo.loadLabel(pm));
            ctrlAppStatusTitle.setTextColor(Color.rgb(0xff, 0xff, 0xff));

            if (ctrlAppUpdated && currentlyPlaying.isPlaying()) {
                // invoke play_pause button to switch the app
                MediaPlayback mediaPlayback = MediaPlayback.getInstance();
                mediaPlayback.action_play_pause();
            }
            SharedPreferences.Editor editor = sharedPref.edit();
            editor.putBoolean("ControlledAppUpdated", false);
            editor.apply();

            appLogo.setImageDrawable(appInfo.loadIcon(pm));
        } catch (PackageManager.NameNotFoundException e) {
            ctrlAppStatusTitle.setText("Please go to the settings and setup controlled music application");
            ctrlAppStatusTitle.setTextColor(Color.rgb(0xff, 0x00, 0x00));

            appLogo.setImageDrawable(ContextCompat.getDrawable(this, (R.drawable.questionmark)));
        }
    } catch (Exception e) {
        PodEmuLog.printStackTrace(e);
        throw e;
    }

}

From source file:org.fdroid.fdroid.privileged.views.UninstallDialogActivity.java

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final Intent intent = getIntent();
    final String packageName = intent.getStringExtra(Installer.EXTRA_PACKAGE_NAME);

    PackageManager pm = getPackageManager();

    ApplicationInfo appInfo;
    try {/*from   ww  w .  jav  a 2s.  co  m*/
        //noinspection WrongConstant (lint is actually wrong here!)
        appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES);
    } catch (PackageManager.NameNotFoundException e) {
        throw new RuntimeException("Failed to get ApplicationInfo for uninstalling");
    }

    final boolean isSystem = (appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
    final boolean isUpdate = (appInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0;

    if (isSystem && !isUpdate) {
        // Cannot remove system apps unless we're uninstalling updates
        throw new RuntimeException("Cannot remove system apps unless we're uninstalling updates");
    }

    int messageId;
    if (isUpdate) {
        messageId = R.string.uninstall_update_confirm;
    } else {
        messageId = R.string.uninstall_confirm;
    }

    // hack to get theme applied (which is not automatically applied due to activity's Theme.NoDisplay
    ContextThemeWrapper theme = new ContextThemeWrapper(this, FDroidApp.getCurThemeResId());

    final AlertDialog.Builder builder = new AlertDialog.Builder(theme);
    builder.setTitle(appInfo.loadLabel(pm));
    builder.setIcon(appInfo.loadIcon(pm));
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Intent data = new Intent();
            data.putExtra(Installer.EXTRA_PACKAGE_NAME, packageName);
            setResult(Activity.RESULT_OK, intent);
            finish();
        }
    });
    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            setResult(Activity.RESULT_CANCELED);
            finish();
        }
    });
    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            setResult(Activity.RESULT_CANCELED);
            finish();
        }
    });
    builder.setMessage(messageId);
    builder.create().show();
}

From source file:es.javocsoft.android.lib.toolbox.ToolBox.java

/**
 * gets the application icon./*from  w ww  . j a v  a 2s. c o  m*/
 * 
 * @param context
 * @param packageName
 * @return
 */
public static Drawable appInfo_getIconFromPackageName(Context context, String packageName) {
    PackageManager pm = context.getPackageManager();
    ApplicationInfo appInfo = null;
    try {
        appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
    } catch (NameNotFoundException e) {
        return null;
    }

    return appInfo.loadIcon(pm);
}