Java Code Examples for android.content.pm.PackageManager#getDefaultActivityIcon()

The following examples show how to use android.content.pm.PackageManager#getDefaultActivityIcon() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: android_9.0.0_r45   File: SearchDialog.java    License: Apache License 2.0 6 votes vote down vote up
private void updateSearchAppIcon() {
    PackageManager pm = getContext().getPackageManager();
    Drawable icon;
    try {
        ActivityInfo info = pm.getActivityInfo(mLaunchComponent, 0);
        icon = pm.getApplicationIcon(info.applicationInfo);
        if (DBG)
            Log.d(LOG_TAG, "Using app-specific icon");
    } catch (NameNotFoundException e) {
        icon = pm.getDefaultActivityIcon();
        Log.w(LOG_TAG, mLaunchComponent + " not found, using generic app icon");
    }
    mAppIcon.setImageDrawable(icon);
    mAppIcon.setVisibility(View.VISIBLE);
    mSearchPlate.setPadding(SEARCH_PLATE_LEFT_PADDING_NON_GLOBAL, mSearchPlate.getPaddingTop(), mSearchPlate.getPaddingRight(), mSearchPlate.getPaddingBottom());
}
 
Example 2
Source Project: Taskbar   File: IconCache.java    License: Apache License 2.0 5 votes vote down vote up
private Drawable getIcon(PackageManager pm, LauncherActivityInfo appInfo) {
    try {
        return appInfo.getBadgedIcon(0);
    } catch (NullPointerException e) {
        return pm.getDefaultActivityIcon();
    }
}
 
Example 3
Source Project: island   File: AppInfo.java    License: Apache License 2.0 5 votes vote down vote up
private Drawable loadUnbadgedIconCompat(final PackageManager pm) {
	if (SDK_INT >= LOLLIPOP_MR1) try {
		return loadUnbadgedIcon(pm);
	} catch (final SecurityException e) {		// Appears on some Samsung devices (e.g. Galaxy S7, Note 8) with Android 8.0
		Analytics.$().logAndReport(TAG, "Error loading unbadged icon for " + this, e);
	}
	Drawable dr = null;
	if (packageName != null) dr = pm.getDrawable(packageName, icon, this);
	if (dr == null) dr = pm.getDefaultActivityIcon();
	return dr;
}
 
Example 4
@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  setContentView(R.layout.label_manager_labels);

  final Intent intent = getIntent();
  if (!intent.hasExtra(EXTRA_PACKAGE_NAME)) {
    throw new IllegalArgumentException("Intent missing package name extra.");
  }

  packageName = intent.getStringExtra(EXTRA_PACKAGE_NAME);

  final PackageManager packageManager = getPackageManager();
  CharSequence applicationLabel;
  Drawable packageIcon;
  try {
    packageIcon = packageManager.getApplicationIcon(packageName);
    final PackageInfo packageInfo = packageManager.getPackageInfo(packageName, 0);
    applicationLabel = packageManager.getApplicationLabel(packageInfo.applicationInfo);
  } catch (NameNotFoundException e) {
    LogUtils.i(TAG, "Could not load package info for package %s.", packageName);

    packageIcon = packageManager.getDefaultActivityIcon();
    applicationLabel = packageName;
  }

  setTitle(getString(R.string.label_manager_package_title, applicationLabel));

  final ActionBar actionBar = getSupportActionBar();
  actionBar.setIcon(packageIcon);
  actionBar.setDisplayHomeAsUpEnabled(true);

  labelList = (ListView) findViewById(R.id.label_list);
  labelProviderClient = new LabelProviderClient(this, LabelProvider.AUTHORITY);
}
 
Example 5
ApkItem(PackageManager pm, PackageInfo info, String path) {
    try {
        icon = pm.getApplicationIcon(info.applicationInfo);
    } catch (Exception e) {
        icon = pm.getDefaultActivityIcon();
    }
    title = pm.getApplicationLabel(info.applicationInfo);
    versionName = info.versionName;
    versionCode = info.versionCode;
    apkfile = path;
    packageInfo = info;
}
 
Example 6
Source Project: ActivityLauncher   File: IconListAdapter.java    License: ISC License 5 votes vote down vote up
static Drawable getIcon(String icon_resource_string, PackageManager pm) {
    try {
        String pack = icon_resource_string.substring(0, icon_resource_string.indexOf(':'));
        String type = icon_resource_string.substring(icon_resource_string.indexOf(':') + 1, icon_resource_string.indexOf('/'));
        String name = icon_resource_string.substring(icon_resource_string.indexOf('/') + 1);
        Resources res = pm.getResourcesForApplication(pack);
        return res.getDrawable(res.getIdentifier(name, type, pack));
    } catch (Exception e) {
        return pm.getDefaultActivityIcon();
    }

}