本文整理汇总了Java中android.content.pm.ApplicationInfo.loadLabel方法的典型用法代码示例。如果您正苦于以下问题:Java ApplicationInfo.loadLabel方法的具体用法?Java ApplicationInfo.loadLabel怎么用?Java ApplicationInfo.loadLabel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.pm.ApplicationInfo
的用法示例。
在下文中一共展示了ApplicationInfo.loadLabel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getLabel
import android.content.pm.ApplicationInfo; //导入方法依赖的package包/类
private CharSequence getLabel(Context context, String packageName) {
PackageManager packageManager = context.getPackageManager();
ApplicationInfo applicationInfo;
try {
applicationInfo = packageManager.getApplicationInfo(packageName, 0);
} catch (PackageManager.NameNotFoundException e) {
return null;
}
Intent launchIntent = packageManager.getLaunchIntentForPackage(packageName);
CharSequence label = null;
if (launchIntent == null) {
label = applicationInfo.loadLabel(packageManager);
} else {
ResolveInfo resolveInfo = packageManager.resolveActivity(launchIntent, 0);
if (resolveInfo != null) {
label = resolveInfo.activityInfo.loadLabel(packageManager);
}
}
return label;
}
示例2: loadInBackground
import android.content.pm.ApplicationInfo; //导入方法依赖的package包/类
@Override
public List<Item> loadInBackground() {
final Context context = getContext();
List<ApplicationInfo> infos = packageManager.getInstalledApplications(GET_NO_TAG);
if (infos == null){
infos = new ArrayList<>();
}
List<Item> items = new ArrayList<>(infos.size());
for (ApplicationInfo info : infos) {
String pkg = info.packageName;
String label;
Drawable icon;
Intent intent;
CharSequence sequence = info.loadLabel(context.getPackageManager());
label = sequence != null ? sequence.toString() : info.packageName;
icon = info.loadIcon(context.getPackageManager());
icon = icon != null ?
icon
: context.getResources().getDrawable(android.R.drawable.sym_def_app_icon,null);
intent = packageManager.getLaunchIntentForPackage(info.packageName);
if (packageManager.getLaunchIntentForPackage(pkg) != null){
App app = new App(info,label,icon,intent);
items.add(app);
}
}
Collections.sort(items, Item.ALPHA_COMPARATOR);
return items;
}
示例3: onClick
import android.content.pm.ApplicationInfo; //导入方法依赖的package包/类
@Override
public void onClick(View v) {
if (group != null && perm != null) {
if (dialog != null) {
dialog.dismiss();
}
PackageManager pm = getContext().getPackageManager();
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle(group.label);
if (perm.descriptionRes != 0) {
builder.setMessage(perm.loadDescription(pm));
} else {
CharSequence appName;
try {
ApplicationInfo app = pm.getApplicationInfo(perm.packageName, 0);
appName = app.loadLabel(pm);
} catch (NameNotFoundException e) {
appName = perm.packageName;
}
builder.setMessage(getContext().getString(
R.string.perms_description_app, appName) + "\n\n" + perm.name);
}
builder.setCancelable(true);
builder.setIcon(group.loadGroupIcon(getContext(), pm));
dialog = builder.show();
dialog.setCanceledOnTouchOutside(true);
}
}
示例4: setPermissions
import android.content.pm.ApplicationInfo; //导入方法依赖的package包/类
private void setPermissions(List<MyPermissionInfo> permList) {
if (permList != null) {
// First pass to group permissions
for (MyPermissionInfo pInfo : permList) {
if (!isDisplayablePermission(pInfo, pInfo.existingReqFlags)) {
continue;
}
MyPermissionGroupInfo group = permGroups.get(pInfo.group);
if (group != null) {
pInfo.label = pInfo.loadLabel(pm);
addPermToList(group.allPermissions, pInfo);
if (pInfo.newPerm) {
addPermToList(group.newPermissions, pInfo);
}
}
}
}
for (MyPermissionGroupInfo pgrp : permGroups.values()) {
if (pgrp.labelRes != 0 || pgrp.nonLocalizedLabel != null) {
pgrp.label = pgrp.loadLabel(pm);
} else {
try {
ApplicationInfo app = pm.getApplicationInfo(pgrp.packageName, 0);
pgrp.label = app.loadLabel(pm);
} catch (NameNotFoundException e) {
pgrp.label = pgrp.loadLabel(pm);
}
}
permGroupsList.add(pgrp);
}
Collections.sort(permGroupsList, permGroupComparator);
}
示例5: copyDocument
import android.content.pm.ApplicationInfo; //导入方法依赖的package包/类
@Override
public String copyDocument(String sourceDocumentId, String targetParentDocumentId) throws FileNotFoundException {
final String packageName = getPackageForDocId(sourceDocumentId);
String fromFilePath = "";
String fileName = "";
try {
PackageInfo packageInfo = packageManager.getPackageInfo(packageName, 0);
ApplicationInfo appInfo = packageInfo.applicationInfo;
fromFilePath = appInfo.sourceDir;
fileName = (String) (appInfo.loadLabel(packageManager) != null ? appInfo.loadLabel(packageManager) : appInfo.packageName);
fileName += getAppVersion(packageInfo.versionName);
} catch (Exception e) {
}
final File fileFrom = new File(fromFilePath);
final File fileTo = Utils.getAppsBackupFile(getContext());
if(!fileTo.exists()){
fileTo.mkdir();
}
if (!FileUtils.moveDocument(fileFrom, fileTo, fileName)) {
throw new IllegalStateException("Failed to copy " + fileFrom);
}
else{
FileUtils.updateMediaStore(getContext(), FileUtils.makeFilePath(fileTo.getPath(),
fileName +"."+ FileUtils.getExtFromFilename(fileFrom.getPath())));
}
return fromFilePath;
}
示例6: convertPackageInfoToAppData
import android.content.pm.ApplicationInfo; //导入方法依赖的package包/类
private List<AppInfo> convertPackageInfoToAppData(Context context, List<PackageInfo> pkgList, boolean fastOpen) {
PackageManager pm = context.getPackageManager();
List<AppInfo> list = new ArrayList<>(pkgList.size());
String hostPkg = VirtualCore.get().getHostPkg();
for (PackageInfo pkg : pkgList) {
// ignore the host package
if (hostPkg.equals(pkg.packageName)) {
continue;
}
// ignore the System package
if (isSystemApplication(pkg)) {
continue;
}
ApplicationInfo ai = pkg.applicationInfo;
String path = ai.publicSourceDir != null ? ai.publicSourceDir : ai.sourceDir;
if (path == null) {
continue;
}
AppInfo info = new AppInfo();
info.packageName = pkg.packageName;
info.fastOpen = fastOpen;
info.path = path;
info.icon = ai.loadIcon(pm);
info.name = ai.loadLabel(pm);
InstalledAppInfo installedAppInfo = VirtualCore.get().getInstalledAppInfo(pkg.packageName, 0);
if (installedAppInfo != null) {
info.cloneCount = installedAppInfo.getInstalledUsers().length;
}
list.add(info);
}
return list;
}
示例7: loadData
import android.content.pm.ApplicationInfo; //导入方法依赖的package包/类
private void loadData(Context context, ApplicationInfo appInfo) {
if (appInfo == null) {
return;
}
PackageManager pm = context.getPackageManager();
try {
CharSequence sequence = appInfo.loadLabel(pm);
if (sequence != null) {
name = sequence.toString();
}
icon = appInfo.loadIcon(pm);
} catch (Throwable e) {
e.printStackTrace();
}
}
示例8: AppMarket
import android.content.pm.ApplicationInfo; //导入方法依赖的package包/类
public AppMarket(Context context, ActivityInfo activityInfo) {
packageName = activityInfo.packageName;
ApplicationInfo appInfo = activityInfo.applicationInfo;
path = appInfo.publicSourceDir;
PackageManager pm = context.getPackageManager();
try {
CharSequence sequence = appInfo.loadLabel(pm);
if (sequence != null) {
name = sequence.toString();
}
icon = appInfo.loadIcon(pm);
} catch (Throwable e) {
e.printStackTrace();
}
}
示例9: getEntryForPackageLocked
import android.content.pm.ApplicationInfo; //导入方法依赖的package包/类
/**
* Gets an entry for the package, which can be used as a fallback entry for various components.
* This method is not thread safe, it must be called from a synchronized method.
*/
private CacheEntry getEntryForPackageLocked(String packageName, UserHandleCompat user,
boolean useLowResIcon) {
ComponentKey cacheKey = getPackageKey(packageName, user);
CacheEntry entry = mCache.get(cacheKey);
if (entry == null || (entry.isLowResIcon && !useLowResIcon)) {
entry = new CacheEntry();
boolean entryUpdated = true;
// Check the DB first.
if (!getEntryFromDB(cacheKey, entry, useLowResIcon)) {
try {
int flags = UserHandleCompat.myUserHandle().equals(user) ? 0 :
PackageManager.GET_UNINSTALLED_PACKAGES;
PackageInfo info = mPackageManager.getPackageInfo(packageName, flags);
ApplicationInfo appInfo = info.applicationInfo;
if (appInfo == null) {
throw new NameNotFoundException("ApplicationInfo is null");
}
// Load the full res icon for the application, but if useLowResIcon is set, then
// only keep the low resolution icon instead of the larger full-sized icon
Bitmap icon = Utilities.createBadgedIconBitmap(
appInfo.loadIcon(mPackageManager), user, mContext);
Bitmap lowResIcon = generateLowResIcon(icon, mPackageBgColor);
entry.title = appInfo.loadLabel(mPackageManager);
entry.contentDescription = mUserManager.getBadgedLabelForUser(entry.title, user);
entry.icon = useLowResIcon ? lowResIcon : icon;
entry.isLowResIcon = useLowResIcon;
// Add the icon in the DB here, since these do not get written during
// package updates.
ContentValues values =
newContentValues(icon, lowResIcon, entry.title.toString(), packageName);
addIconToDB(values, cacheKey.componentName, info,
mUserManager.getSerialNumberForUser(user));
} catch (NameNotFoundException e) {
if (DEBUG) Log.d(TAG, "Application not installed " + packageName);
entryUpdated = false;
}
}
// Only add a filled-out entry to the cache
if (entryUpdated) {
mCache.put(cacheKey, entry);
}
}
return entry;
}
示例10: getEntryForPackageLocked
import android.content.pm.ApplicationInfo; //导入方法依赖的package包/类
/**
* Gets an entry for the package, which can be used as a fallback entry for various components.
* This method is not thread safe, it must be called from a synchronized method.
*/
private CacheEntry getEntryForPackageLocked(String packageName, UserHandle user,
boolean useLowResIcon) {
ComponentKey cacheKey = getPackageKey(packageName, user);
CacheEntry entry = mCache.get(cacheKey);
if (entry == null || (entry.isLowResIcon && !useLowResIcon)) {
entry = new CacheEntry();
boolean entryUpdated = true;
// Check the DB first.
if (!getEntryFromDB(cacheKey, entry, useLowResIcon)) {
try {
int uninstalled = android.os.Build.VERSION.SDK_INT >= 24 ? PackageManager.MATCH_UNINSTALLED_PACKAGES : PackageManager.GET_UNINSTALLED_PACKAGES;
int flags = Process.myUserHandle().equals(user) ? 0 : uninstalled;
PackageInfo info = mPackageManager.getPackageInfo(packageName, flags);
ApplicationInfo appInfo = info.applicationInfo;
if (appInfo == null) {
throw new NameNotFoundException("ApplicationInfo is null");
}
// Load the full res icon for the application, but if useLowResIcon is set, then
// only keep the low resolution icon instead of the larger full-sized icon
Bitmap icon = LauncherIcons.createBadgedIconBitmap(
appInfo.loadIcon(mPackageManager), user, mContext, appInfo.targetSdkVersion);
Bitmap lowResIcon = generateLowResIcon(icon, mPackageBgColor);
entry.title = appInfo.loadLabel(mPackageManager);
entry.contentDescription = mUserManager.getBadgedLabelForUser(entry.title, user);
entry.icon = useLowResIcon ? lowResIcon : icon;
entry.isLowResIcon = useLowResIcon;
// Add the icon in the DB here, since these do not get written during
// package updates.
ContentValues values =
newContentValues(icon, lowResIcon, entry.title.toString(), packageName);
addIconToDB(values, cacheKey.componentName, info,
mUserManager.getSerialNumberForUser(user));
} catch (NameNotFoundException e) {
e.printStackTrace();
entryUpdated = false;
}
}
// Only add a filled-out entry to the cache
if (entryUpdated) {
mCache.put(cacheKey, entry);
}
}
return entry;
}
示例11: setFromPackageInfo
import android.content.pm.ApplicationInfo; //导入方法依赖的package包/类
private void setFromPackageInfo(PackageManager pm, PackageInfo packageInfo) {
this.packageName = packageInfo.packageName;
final String installerPackageName = pm.getInstallerPackageName(packageName);
CharSequence installerPackageLabel = null;
if (!TextUtils.isEmpty(installerPackageName)) {
try {
ApplicationInfo installerAppInfo = pm.getApplicationInfo(installerPackageName,
PackageManager.GET_META_DATA);
installerPackageLabel = installerAppInfo.loadLabel(pm);
} catch (PackageManager.NameNotFoundException e) {
Log.w(TAG, "Could not get app info: " + installerPackageName, e);
}
}
if (TextUtils.isEmpty(installerPackageLabel)) {
installerPackageLabel = installerPackageName;
}
ApplicationInfo appInfo = packageInfo.applicationInfo;
final CharSequence appDescription = appInfo.loadDescription(pm);
if (TextUtils.isEmpty(appDescription)) {
this.summary = "(installed by " + installerPackageLabel + ")";
} else if (appDescription.length() > 40) {
this.summary = (String) appDescription.subSequence(0, 40);
} else {
this.summary = (String) appDescription;
}
this.added = new Date(packageInfo.firstInstallTime);
this.lastUpdated = new Date(packageInfo.lastUpdateTime);
this.description = "<p>";
if (!TextUtils.isEmpty(appDescription)) {
this.description += appDescription + "\n";
}
this.description += "(installed by " + installerPackageLabel
+ ", first installed on " + this.added
+ ", last updated on " + this.lastUpdated + ")</p>";
this.name = (String) appInfo.loadLabel(pm);
this.icon = getIconName(packageName, packageInfo.versionCode);
this.installedVersionName = packageInfo.versionName;
this.installedVersionCode = packageInfo.versionCode;
this.compatible = true;
}
示例12: createShortcut
import android.content.pm.ApplicationInfo; //导入方法依赖的package包/类
public boolean createShortcut(int userId, String packageName, Intent splash, OnEmitShortcutListener listener) {
InstalledAppInfo setting = getInstalledAppInfo(packageName, 0);
if (setting == null) {
return false;
}
ApplicationInfo appInfo = setting.getApplicationInfo(userId);
PackageManager pm = context.getPackageManager();
String name;
Bitmap icon;
try {
CharSequence sequence = appInfo.loadLabel(pm);
name = sequence.toString();
icon = BitmapUtils.drawableToBitmap(appInfo.loadIcon(pm));
} catch (Throwable e) {
return false;
}
if (listener != null) {
String newName = listener.getName(name);
if (newName != null) {
name = newName;
}
Bitmap newIcon = listener.getIcon(icon);
if (newIcon != null) {
icon = newIcon;
}
}
Intent targetIntent = getLaunchIntent(packageName, userId);
if (targetIntent == null) {
return false;
}
Intent shortcutIntent = new Intent();
shortcutIntent.setClassName(getHostPkg(), Constants.SHORTCUT_PROXY_ACTIVITY_NAME);
shortcutIntent.addCategory(Intent.CATEGORY_DEFAULT);
if (splash != null) {
shortcutIntent.putExtra("_VA_|_splash_", splash.toUri(0));
}
shortcutIntent.putExtra("_VA_|_intent_", targetIntent);
shortcutIntent.putExtra("_VA_|_uri_", targetIntent.toUri(0));
shortcutIntent.putExtra("_VA_|_user_id_", VUserHandle.myUserId());
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon);
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
context.sendBroadcast(addIntent);
return true;
}
示例13: removeShortcut
import android.content.pm.ApplicationInfo; //导入方法依赖的package包/类
public boolean removeShortcut(int userId, String packageName, Intent splash, OnEmitShortcutListener listener) {
InstalledAppInfo setting = getInstalledAppInfo(packageName, 0);
if (setting == null) {
return false;
}
ApplicationInfo appInfo = setting.getApplicationInfo(userId);
PackageManager pm = context.getPackageManager();
String name;
try {
CharSequence sequence = appInfo.loadLabel(pm);
name = sequence.toString();
} catch (Throwable e) {
return false;
}
if (listener != null) {
String newName = listener.getName(name);
if (newName != null) {
name = newName;
}
}
Intent targetIntent = getLaunchIntent(packageName, userId);
if (targetIntent == null) {
return false;
}
Intent shortcutIntent = new Intent();
shortcutIntent.setClassName(getHostPkg(), Constants.SHORTCUT_PROXY_ACTIVITY_NAME);
shortcutIntent.addCategory(Intent.CATEGORY_DEFAULT);
if (splash != null) {
shortcutIntent.putExtra("_VA_|_splash_", splash.toUri(0));
}
shortcutIntent.putExtra("_VA_|_intent_", targetIntent);
shortcutIntent.putExtra("_VA_|_uri_", targetIntent.toUri(0));
shortcutIntent.putExtra("_VA_|_user_id_", VUserHandle.myUserId());
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
addIntent.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
context.sendBroadcast(addIntent);
return true;
}
示例14: createShortcut
import android.content.pm.ApplicationInfo; //导入方法依赖的package包/类
public boolean createShortcut(int userId, String packageName, Intent splash, OnEmitShortcutListener listener) {
InstalledAppInfo setting = getInstalledAppInfo(packageName, 0);
if (setting == null) {
return false;
}
ApplicationInfo appInfo = setting.getApplicationInfo(userId);
PackageManager pm = context.getPackageManager();
String name;
Bitmap icon;
try {
CharSequence sequence = appInfo.loadLabel(pm);
name = sequence.toString();
icon = BitmapUtils.drawableToBitmap(appInfo.loadIcon(pm));
} catch (Throwable e) {
return false;
}
if (listener != null) {
String newName = listener.getName(name);
if (newName != null) {
name = newName;
}
Bitmap newIcon = listener.getIcon(icon);
if (newIcon != null) {
icon = newIcon;
}
}
Intent targetIntent = getLaunchIntent(packageName, userId);
if (targetIntent == null) {
return false;
}
Intent shortcutIntent = new Intent();
shortcutIntent.setClassName(getHostPkg(), Constants.SHORTCUT_PROXY_ACTIVITY_NAME);
shortcutIntent.addCategory(Intent.CATEGORY_DEFAULT);
if (splash != null) {
shortcutIntent.putExtra("_VA_|_splash_", splash.toUri(0));
}
shortcutIntent.putExtra("_VA_|_intent_", targetIntent);
shortcutIntent.putExtra("_VA_|_uri_", targetIntent.toUri(0));
shortcutIntent.putExtra("_VA_|_user_id_", userId);
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon);
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
context.sendBroadcast(addIntent);
return true;
}
示例15: createShortcut
import android.content.pm.ApplicationInfo; //导入方法依赖的package包/类
public boolean createShortcut(int userId, String packageName, Intent splash, OnEmitShortcutListener listener) {
AppSetting setting = findApp(packageName);
if (setting == null) {
return false;
}
ApplicationInfo appInfo = setting.getApplicationInfo(userId);
PackageManager pm = context.getPackageManager();
String name;
Bitmap icon;
try {
CharSequence sequence = appInfo.loadLabel(pm);
name = sequence.toString();
icon = BitmapUtils.drawableToBitmap(appInfo.loadIcon(pm));
} catch (Throwable e) {
return false;
}
if (listener != null) {
String newName = listener.getName(name);
if (newName != null) {
name = newName;
}
Bitmap newIcon = listener.getIcon(icon);
if (newIcon != null) {
icon = newIcon;
}
}
Intent targetIntent = getLaunchIntent(packageName, userId);
if (targetIntent == null) {
return false;
}
Intent shortcutIntent = new Intent();
shortcutIntent.setClassName(getHostPkg(), Constants.SHORTCUT_PROXY_ACTIVITY_NAME);
shortcutIntent.addCategory(Intent.CATEGORY_DEFAULT);
if (splash != null) {
shortcutIntent.putExtra("_VA_|_splash_", splash.toUri(0));
}
shortcutIntent.putExtra("_VA_|_intent_", targetIntent);
shortcutIntent.putExtra("_VA_|_uri_", targetIntent.toUri(0));
shortcutIntent.putExtra("_VA_|_user_id_", VUserHandle.myUserId());
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon);
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
context.sendBroadcast(addIntent);
return true;
}