本文整理匯總了Java中android.content.pm.PackageManager.getDrawable方法的典型用法代碼示例。如果您正苦於以下問題:Java PackageManager.getDrawable方法的具體用法?Java PackageManager.getDrawable怎麽用?Java PackageManager.getDrawable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.content.pm.PackageManager
的用法示例。
在下文中一共展示了PackageManager.getDrawable方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getActivityIcon
import android.content.pm.PackageManager; //導入方法依賴的package包/類
/**
* 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;
}
示例2: getActivityIcon
import android.content.pm.PackageManager; //導入方法依賴的package包/類
private Drawable getActivityIcon(ComponentName component) {
PackageManager pm = this.mContext.getPackageManager();
try {
ActivityInfo activityInfo = pm.getActivityInfo(component, 128);
int iconId = activityInfo.getIconResource();
if (iconId == 0) {
return null;
}
Drawable drawable = pm.getDrawable(component.getPackageName(), iconId, activityInfo.applicationInfo);
if (drawable != null) {
return drawable;
}
Log.w(LOG_TAG, "Invalid icon resource " + iconId + " for " + component.flattenToShortString());
return null;
} catch (NameNotFoundException ex) {
Log.w(LOG_TAG, ex.toString());
return null;
}
}
示例3: loadPackageIcon
import android.content.pm.PackageManager; //導入方法依賴的package包/類
public static Drawable loadPackageIcon(Context context, String authority, int icon) {
if (icon != 0) {
if (authority != null) {
final PackageManager pm = context.getPackageManager();
final ProviderInfo info = pm.resolveContentProvider(authority, 0);
if (info != null) {
return pm.getDrawable(info.packageName, icon, info.applicationInfo);
}
} else {
return ContextCompat.getDrawable(context, icon);
}
}
return null;
}
示例4: AccountData
import android.content.pm.PackageManager; //導入方法依賴的package包/類
/**
* @param name The name of the account. This is usually the user's email address or
* username.
* @param description The description for this account. This will be dictated by the
* type of account returned, and can be obtained from the system AccountManager.
*/
public AccountData(String name, AuthenticatorDescription description) {
mName = name;
if (description != null) {
mType = description.type;
// The type string is stored in a resource, so we need to convert it into something
// human readable.
String packageName = description.packageName;
PackageManager pm = getPackageManager();
if (description.labelId != 0) {
mTypeLabel = pm.getText(packageName, description.labelId, null);
if (mTypeLabel == null) {
throw new IllegalArgumentException("LabelID provided, but label not found");
}
} else {
mTypeLabel = "";
}
if (description.iconId != 0) {
mIcon = pm.getDrawable(packageName, description.iconId, null);
if (mIcon == null) {
throw new IllegalArgumentException("IconID provided, but drawable not " +
"found");
}
} else {
mIcon = getResources().getDrawable(android.R.drawable.sym_def_app_icon);
}
}
}
示例5: loadIcon
import android.content.pm.PackageManager; //導入方法依賴的package包/類
/**
* Load icon
*
* @param packageManager package manager
* @param packageName package name
* @param iconId icon id
* @return drawable
*/
static public Drawable loadIcon(@NonNull final PackageManager packageManager, final String packageName, final int iconId)
{
if (iconId != 0)
{
return packageManager.getDrawable(packageName, iconId, null);
}
return packageManager.getDefaultActivityIcon();
}