本文整理汇总了Java中android.content.pm.PackageManager.getActivityIcon方法的典型用法代码示例。如果您正苦于以下问题:Java PackageManager.getActivityIcon方法的具体用法?Java PackageManager.getActivityIcon怎么用?Java PackageManager.getActivityIcon使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.pm.PackageManager
的用法示例。
在下文中一共展示了PackageManager.getActivityIcon方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: preloadIcon
import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
* Pre-load an icon into the persistent cache.
*
* <P>Queries for a component that does not exist in the package manager
* will be answered by the persistent cache.
*
* @param componentName the icon should be returned for this component
* @param icon the icon to be persisted
* @param dpi the native density of the icon
*/
public void preloadIcon(ComponentName componentName, Bitmap icon, int dpi, String label,
long userSerial, InvariantDeviceProfile idp) {
// TODO rescale to the correct native DPI
try {
PackageManager packageManager = mContext.getPackageManager();
packageManager.getActivityIcon(componentName);
// component is present on the system already, do nothing
return;
} catch (PackageManager.NameNotFoundException e) {
// pass
}
icon = Bitmap.createScaledBitmap(icon, idp.iconBitmapSize, idp.iconBitmapSize, true);
Bitmap lowResIcon = generateLowResIcon(icon, Color.TRANSPARENT);
ContentValues values = newContentValues(icon, lowResIcon, label,
componentName.getPackageName());
values.put(IconDB.COLUMN_COMPONENT, componentName.flattenToString());
values.put(IconDB.COLUMN_USER, userSerial);
mIconDb.insertOrReplace(values);
}