Java Code Examples for android.content.pm.PackageManager.getText()

The following are Jave code examples for showing how to use getText() of the android.content.pm.PackageManager class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Seconds   File: ActivityMain.java   View Source Code Vote up 5 votes
/**
 * 获取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;
}
 
Example 2
Project: buildAPKsSamples   File: ContactAdder.java   View Source Code Vote up 5 votes
/**
 * @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);
        }
    }
}
 
Example 3
Project: Treebolic   File: Services.java   View Source Code Vote up 5 votes
/**
 * 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 "?";
}