Java Code Examples for android.content.pm.activityinfo#getIconResource()

The following examples show how to use android.content.pm.activityinfo#getIconResource() . 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 check out the related API usage on the sidebar.
Example 1
Source File: SuggestionsAdapter.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the activity or application icon for an activity.
 *
 * @param component Name of an activity.
 * @return A drawable, or {@code null} if neither the acitivy or the application
 *         have an icon set.
 */
private Drawable getActivityIcon(ComponentName component) {
    PackageManager pm = mContext.getPackageManager();
    final ActivityInfo activityInfo;
    try {
        activityInfo = pm.getActivityInfo(component, PackageManager.GET_META_DATA);
    } catch (NameNotFoundException ex) {
        Log.w(LOG_TAG, ex.toString());
        return null;
    }
    int iconId = activityInfo.getIconResource();
    if (iconId == 0) return null;
    String pkg = component.getPackageName();
    Drawable drawable = pm.getDrawable(pkg, iconId, activityInfo.applicationInfo);
    if (drawable == null) {
        Log.w(LOG_TAG, "Invalid icon resource " + iconId + " for "
                + component.flattenToShortString());
        return null;
    }
    return drawable;
}
 
Example 2
Source File: IconCache.java    From LaunchEnr with GNU General Public License v3.0 6 votes vote down vote up
public Drawable getFullResIcon(ActivityInfo info) {
    Resources resources;
    try {
        resources = mPackageManager.getResourcesForApplication(
                info.applicationInfo);
    } catch (PackageManager.NameNotFoundException e) {
        resources = null;
    }
    if (resources != null) {
        int iconId = info.getIconResource();
        if (iconId != 0) {
            return getFullResIcon(resources, iconId);
        }
    }

    return getFullResDefaultActivityIcon();
}
 
Example 3
Source File: SuggestionsAdapter.java    From CSipSimple with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets the activity or application icon for an activity.
 *
 * @param component Name of an activity.
 * @return A drawable, or {@code null} if neither the acitivy or the application
 *         have an icon set.
 */
private Drawable getActivityIcon(ComponentName component) {
    PackageManager pm = mContext.getPackageManager();
    final ActivityInfo activityInfo;
    try {
        activityInfo = pm.getActivityInfo(component, PackageManager.GET_META_DATA);
    } catch (NameNotFoundException ex) {
        Log.w(LOG_TAG, ex.toString());
        return null;
    }
    int iconId = activityInfo.getIconResource();
    if (iconId == 0) return null;
    String pkg = component.getPackageName();
    Drawable drawable = pm.getDrawable(pkg, iconId, activityInfo.applicationInfo);
    if (drawable == null) {
        Log.w(LOG_TAG, "Invalid icon resource " + iconId + " for "
                + component.flattenToShortString());
        return null;
    }
    return drawable;
}
 
Example 4
Source File: IconCache.java    From Trebuchet with GNU General Public License v3.0 6 votes vote down vote up
public Drawable getFullResIcon(ActivityInfo info) {
    Resources resources;
    try {
        resources = mPackageManager.getResourcesForApplication(
                info.applicationInfo);
    } catch (PackageManager.NameNotFoundException e) {
        resources = null;
    }
    if (resources != null) {
        int iconId = info.getIconResource();
        if (iconId != 0) {
            return getFullResIcon(resources, iconId);
        }
    }

    return getFullResDefaultActivityIcon();
}
 
Example 5
Source File: IconCache.java    From TurboLauncher with Apache License 2.0 6 votes vote down vote up
public Drawable getFullResIcon(ActivityInfo info) {

		Resources resources;
		try {
			resources = mPackageManager
					.getResourcesForApplication(info.applicationInfo);
		} catch (PackageManager.NameNotFoundException e) {
			resources = null;
		}
		if (resources != null) {
			int iconId = info.getIconResource();
			if (iconId != 0) {
				return getFullResIcon(resources, iconId);
			}
		}

		return getFullResDefaultActivityIcon();
	}
 
Example 6
Source File: IconCache.java    From FastAccess with GNU General Public License v3.0 6 votes vote down vote up
public Drawable getFullResIcon(ActivityInfo info) {
    Resources resources;
    try {
        resources = mPackageManager.getResourcesForApplication(info.applicationInfo);
    } catch (PackageManager.NameNotFoundException e) {
        resources = null;
    }
    if (resources != null) {
        int iconId = 0;
        if (mIconPackHelper != null && mIconPackHelper.isIconPackLoaded()) {
            iconId = mIconPackHelper.getResourceIdForActivityIcon(info);
            if (iconId != 0) {
                return getFullResIcon(mIconPackHelper.getIconPackResources(), iconId);
            }
        }
        iconId = info.getIconResource();
        if (iconId != 0) {
            return getFullResIcon(resources, iconId);
        }
    }
    return getFullResDefaultActivityIcon();
}
 
Example 7
Source File: IconCache.java    From LB-Launcher with Apache License 2.0 6 votes vote down vote up
public Drawable getFullResIcon(ActivityInfo info) {
    Resources resources;
    try {
        resources = mPackageManager.getResourcesForApplication(
                info.applicationInfo);
    } catch (PackageManager.NameNotFoundException e) {
        resources = null;
    }
    if (resources != null) {
        int iconId = info.getIconResource();
        if (iconId != 0) {
            return getFullResIcon(resources, iconId);
        }
    }

    return getFullResDefaultActivityIcon();
}
 
Example 8
Source File: SuggestionsAdapter.java    From zen4android with MIT License 6 votes vote down vote up
/**
 * Gets the activity or application icon for an activity.
 *
 * @param component Name of an activity.
 * @return A drawable, or {@code null} if neither the acitivy or the application
 *         have an icon set.
 */
private Drawable getActivityIcon(ComponentName component) {
    PackageManager pm = mContext.getPackageManager();
    final ActivityInfo activityInfo;
    try {
        activityInfo = pm.getActivityInfo(component, PackageManager.GET_META_DATA);
    } catch (NameNotFoundException ex) {
        Log.w(LOG_TAG, ex.toString());
        return null;
    }
    int iconId = activityInfo.getIconResource();
    if (iconId == 0) return null;
    String pkg = component.getPackageName();
    Drawable drawable = pm.getDrawable(pkg, iconId, activityInfo.applicationInfo);
    if (drawable == null) {
        Log.w(LOG_TAG, "Invalid icon resource " + iconId + " for "
                + component.flattenToShortString());
        return null;
    }
    return drawable;
}
 
Example 9
Source File: IconCacheHelper.java    From Hangar with GNU General Public License v3.0 6 votes vote down vote up
public Drawable getFullResIcon(ActivityInfo info, boolean getStock) {

        Resources resources;
        try {
            resources = mPackageManager.getResourcesForApplication(
                    info.applicationInfo);
        } catch (PackageManager.NameNotFoundException e) {
            resources = null;
        }
        if (resources != null) {
            int iconId;
            if (mIconPackHelper != null && mIconPackHelper.isIconPackLoaded() && !getStock) {
                iconId = mIconPackHelper.getResourceIdForActivityIcon(info);
                if (iconId != 0) {
                    return getFullResIcon(mIconPackHelper.getIconPackResources(), iconId);
                }
            }
            iconId = info.getIconResource();
            if (iconId != 0) {
                return getFullResIcon(resources, iconId);
            }
        }

        return getFullResDefaultActivityIcon();
    }
 
Example 10
Source File: SuggestionsAdapter.java    From zhangshangwuda with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the activity or application icon for an activity.
 *
 * @param component Name of an activity.
 * @return A drawable, or {@code null} if neither the acitivy or the application
 *         have an icon set.
 */
private Drawable getActivityIcon(ComponentName component) {
    PackageManager pm = mContext.getPackageManager();
    final ActivityInfo activityInfo;
    try {
        activityInfo = pm.getActivityInfo(component, PackageManager.GET_META_DATA);
    } catch (NameNotFoundException ex) {
        Log.w(LOG_TAG, ex.toString());
        return null;
    }
    int iconId = activityInfo.getIconResource();
    if (iconId == 0) return null;
    String pkg = component.getPackageName();
    Drawable drawable = pm.getDrawable(pkg, iconId, activityInfo.applicationInfo);
    if (drawable == null) {
        Log.w(LOG_TAG, "Invalid icon resource " + iconId + " for "
                + component.flattenToShortString());
        return null;
    }
    return drawable;
}
 
Example 11
Source File: SuggestionsAdapter.java    From Libraries-for-Android-Developers with MIT License 6 votes vote down vote up
/**
 * Gets the activity or application icon for an activity.
 *
 * @param component Name of an activity.
 * @return A drawable, or {@code null} if neither the acitivy or the application
 *         have an icon set.
 */
private Drawable getActivityIcon(ComponentName component) {
    PackageManager pm = mContext.getPackageManager();
    final ActivityInfo activityInfo;
    try {
        activityInfo = pm.getActivityInfo(component, PackageManager.GET_META_DATA);
    } catch (NameNotFoundException ex) {
        Log.w(LOG_TAG, ex.toString());
        return null;
    }
    int iconId = activityInfo.getIconResource();
    if (iconId == 0) return null;
    String pkg = component.getPackageName();
    Drawable drawable = pm.getDrawable(pkg, iconId, activityInfo.applicationInfo);
    if (drawable == null) {
        Log.w(LOG_TAG, "Invalid icon resource " + iconId + " for "
                + component.flattenToShortString());
        return null;
    }
    return drawable;
}
 
Example 12
Source File: IconCache.java    From KAM with GNU General Public License v3.0 5 votes vote down vote up
public Drawable getFullResIcon(ActivityInfo info) {
    Resources resources;
    try {
        resources = mPackageManager.getResourcesForApplication(info.applicationInfo);
    } catch (PackageManager.NameNotFoundException e) {
        resources = null;
    }
    if (resources != null) {
        int iconId = info.getIconResource();
        if (iconId != 0) {
            return getFullResIcon(resources, iconId);
        }
    }
    return getFullResDefaultActivityIcon();
}