本文整理汇总了Java中android.content.pm.PackageManager.getText方法的典型用法代码示例。如果您正苦于以下问题:Java PackageManager.getText方法的具体用法?Java PackageManager.getText怎么用?Java PackageManager.getText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.pm.PackageManager
的用法示例。
在下文中一共展示了PackageManager.getText方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getData
import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
* 获取Demo列表
*
* @return
*/
private List<Map<String, Object>> getData() {
List<Map<String, Object>> myData = new ArrayList<Map<String, Object>>();
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(CATEGORY_SAMPLE_CODE);
PackageManager pm = getPackageManager();
List<ResolveInfo> list = pm.queryIntentActivities(mainIntent, 0);
if (null == list)
return myData;
int len = list.size();
for (int i = 0; i < len; i++) {
ResolveInfo info = list.get(i);
if (!getPackageName().equalsIgnoreCase(info.activityInfo.packageName)) {
continue;
}
CharSequence labelSeq = info.loadLabel(pm);
CharSequence description = null;
if (info.activityInfo.descriptionRes != 0) {
description = pm.getText(info.activityInfo.packageName,
info.activityInfo.descriptionRes, null);
}
String label = labelSeq != null ? labelSeq.toString() : info.activityInfo.name;
addItem(myData,
label,
activityIntent(info.activityInfo.applicationInfo.packageName,
info.activityInfo.name), description);
}
return myData;
}
示例2: 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);
}
}
}
示例3: loadText
import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
* Load label
*
* @param packageName package name
* @param labelId label id
* @return label
*/
static private String loadText(@NonNull final PackageManager packageManager, final String packageName, final int labelId)
{
if (labelId != 0)
{
final CharSequence label = packageManager.getText(packageName, labelId, null);
return label.toString();
}
return "?";
}