本文整理匯總了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);
}