本文整理汇总了Java中android.content.pm.ResolveInfo.loadLabel方法的典型用法代码示例。如果您正苦于以下问题:Java ResolveInfo.loadLabel方法的具体用法?Java ResolveInfo.loadLabel怎么用?Java ResolveInfo.loadLabel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.pm.ResolveInfo
的用法示例。
在下文中一共展示了ResolveInfo.loadLabel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAvailableThemes
import android.content.pm.ResolveInfo; //导入方法依赖的package包/类
public static HashMap<String, String> getAvailableThemes(Context ctxt){
HashMap<String, String> result = new HashMap<String, String>();
result.put("", ctxt.getResources().getString(R.string.app_name));
PackageManager packageManager = ctxt.getPackageManager();
Intent it = new Intent(SipManager.ACTION_GET_DRAWABLES);
List<ResolveInfo> availables = packageManager.queryBroadcastReceivers(it, 0);
Log.d(THIS_FILE, "We found " + availables.size() + "themes");
for(ResolveInfo resInfo : availables) {
Log.d(THIS_FILE, "We have -- "+resInfo);
ActivityInfo actInfos = resInfo.activityInfo;
ComponentName cmp = new ComponentName(actInfos.packageName, actInfos.name);
String label = (String) actInfos.loadLabel(packageManager);
if(TextUtils.isEmpty(label)) {
label = (String) resInfo.loadLabel(packageManager);
}
result.put(cmp.flattenToString(), label);
}
return result;
}
示例2: querySampleActivities
import android.content.pm.ResolveInfo; //导入方法依赖的package包/类
protected List<SampleInfo> querySampleActivities() {
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.setPackage(getPackageName());
intent.addCategory(Intent.CATEGORY_SAMPLE_CODE);
PackageManager pm = getPackageManager();
List<ResolveInfo> infos = pm.queryIntentActivities(intent, 0);
ArrayList<SampleInfo> samples = new ArrayList<SampleInfo>();
final int count = infos.size();
for (int i = 0; i < count; i++) {
final ResolveInfo info = infos.get(i);
final CharSequence labelSeq = info.loadLabel(pm);
String label = labelSeq != null ? labelSeq.toString() : info.activityInfo.name;
Intent target = new Intent();
target.setClassName(info.activityInfo.applicationInfo.packageName,
info.activityInfo.name);
SampleInfo sample = new SampleInfo(label, target);
samples.add(sample);
}
return samples;
}
示例3: updateAppearance
import android.content.pm.ResolveInfo; //导入方法依赖的package包/类
private void updateAppearance() {
if (this.mAdapter.getCount() > 0) {
this.mExpandActivityOverflowButton.setEnabled(true);
} else {
this.mExpandActivityOverflowButton.setEnabled(false);
}
int activityCount = this.mAdapter.getActivityCount();
int historySize = this.mAdapter.getHistorySize();
if (activityCount == 1 || (activityCount > 1 && historySize > 0)) {
this.mDefaultActivityButton.setVisibility(0);
ResolveInfo activity = this.mAdapter.getDefaultActivity();
PackageManager packageManager = getContext().getPackageManager();
this.mDefaultActivityButtonImage.setImageDrawable(activity.loadIcon(packageManager));
if (this.mDefaultActionButtonContentDescription != 0) {
CharSequence label = activity.loadLabel(packageManager);
this.mDefaultActivityButton.setContentDescription(getContext().getString(this.mDefaultActionButtonContentDescription, new Object[]{label}));
}
} else {
this.mDefaultActivityButton.setVisibility(8);
}
if (this.mDefaultActivityButton.getVisibility() == 0) {
this.mActivityChooserContent.setBackgroundDrawable(this.mActivityChooserContentBackground);
} else {
this.mActivityChooserContent.setBackgroundDrawable(null);
}
}
示例4: handleUnsupportedLink
import android.content.pm.ResolveInfo; //导入方法依赖的package包/类
private static boolean handleUnsupportedLink(final Context context, final IWebView webView, final Intent intent) {
final String fallbackUrl = intent.getStringExtra(EXTRA_BROWSER_FALLBACK_URL);
if (fallbackUrl != null) {
webView.loadUrl(fallbackUrl);
return true;
}
if (intent.getPackage() != null) {
// The url included the target package:
final String marketUri = MARKET_INTENT_URI_PACKAGE_PREFIX + intent.getPackage();
final Intent marketIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(marketUri));
marketIntent.addCategory(Intent.CATEGORY_BROWSABLE);
final PackageManager packageManager = context.getPackageManager();
final ResolveInfo info = packageManager.resolveActivity(marketIntent, 0);
final CharSequence marketTitle = info.loadLabel(packageManager);
showConfirmationDialog(context, marketIntent,
context.getString(R.string.external_app_prompt_no_app_title),
R.string.external_app_prompt_no_app, marketTitle);
// Stop loading, we essentially have a result.
return true;
}
// If there's really no way to handle this, we just let the browser handle this URL
// (which then shows the unsupported protocol page).
return false;
}
示例5: queryAppInfo
import android.content.pm.ResolveInfo; //导入方法依赖的package包/类
public void queryAppInfo() {
PackageManager pm = this.getPackageManager(); // 获得PackageManager对象
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> resolveInfos = pm.queryIntentActivities(mainIntent, 0);
Collections.sort(resolveInfos, new ResolveInfo.DisplayNameComparator(pm));
if (AppProxyManager.Instance.mlistAppInfo != null) {
AppProxyManager.Instance.mlistAppInfo.clear();
for (ResolveInfo reInfo : resolveInfos) {
String pkgName = reInfo.activityInfo.packageName; // 获得应用程序的包名
String appLabel = (String) reInfo.loadLabel(pm); // 获得应用程序的Label
Drawable icon = reInfo.loadIcon(pm); // 获得应用程序图标
AppInfo appInfo = new AppInfo();
appInfo.setAppLabel(appLabel);
appInfo.setPkgName(pkgName);
appInfo.setAppIcon(icon);
if (!appInfo.getPkgName().equals("com.vm.shadowsocks"))//App本身会强制加入代理列表
AppProxyManager.Instance.mlistAppInfo.add(appInfo);
}
}
}
示例6: updateAppearance
import android.content.pm.ResolveInfo; //导入方法依赖的package包/类
/**
* Updates the buttons state.
*/
private void updateAppearance() {
// Expand overflow button.
if (mAdapter.getCount() > 0) {
mExpandActivityOverflowButton.setEnabled(true);
} else {
mExpandActivityOverflowButton.setEnabled(false);
}
// Default activity button.
final int activityCount = mAdapter.getActivityCount();
final int historySize = mAdapter.getHistorySize();
if (activityCount > 0 && historySize > 0) {
mDefaultActivityButton.setVisibility(VISIBLE);
ResolveInfo activity = mAdapter.getDefaultActivity();
PackageManager packageManager = mContext.getPackageManager();
mDefaultActivityButtonImage.setImageDrawable(activity.loadIcon(packageManager));
if (mDefaultActionButtonContentDescription != 0) {
CharSequence label = activity.loadLabel(packageManager);
String contentDescription = mContext.getString(
mDefaultActionButtonContentDescription, label);
mDefaultActivityButton.setContentDescription(contentDescription);
}
// Work-around for #415.
mAdapter.setShowDefaultActivity(false, false);
} else {
mDefaultActivityButton.setVisibility(View.GONE);
}
// Activity chooser content.
if (mDefaultActivityButton.getVisibility() == VISIBLE) {
mActivityChooserContent.setBackgroundDrawable(mActivityChooserContentBackground);
} else {
mActivityChooserContent.setBackgroundDrawable(null);
mActivityChooserContent.setPadding(0, 0, 0, 0);
}
}
示例7: getDisplayName
import android.content.pm.ResolveInfo; //导入方法依赖的package包/类
@Override
public CharSequence getDisplayName() {
if (mDisplayName != null) {
return mDisplayName;
}
ResolveInfo ri = getResolveInfo();
if (ri != null) {
return mDisplayName = ri.loadLabel(mContext.getPackageManager());
}
return null;
}
示例8: getData
import android.content.pm.ResolveInfo; //导入方法依赖的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;
}
示例9: loadApplications
import android.content.pm.ResolveInfo; //导入方法依赖的package包/类
/**
* Loads the list of installed applications in mApplications.
*/
private void loadApplications(boolean isLaunching) {
if (isLaunching && mApplications != null) {
return;
}
PackageManager manager = getPackageManager();
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List<ResolveInfo> apps = manager.queryIntentActivities(mainIntent, 0);
Collections.sort(apps, new ResolveInfo.DisplayNameComparator(manager));
if (apps != null) {
final int count = apps.size();
if (mApplications == null) {
mApplications = new ArrayList<ApplicationInfo>(count);
}
mApplications.clear();
for (int i = 0; i < count; i++) {
ApplicationInfo application = new ApplicationInfo();
ResolveInfo info = apps.get(i);
application.title = info.loadLabel(manager);
application.setActivity(new ComponentName(
info.activityInfo.applicationInfo.packageName,
info.activityInfo.name),
Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
application.icon = info.activityInfo.loadIcon(manager);
mApplications.add(application);
}
}
}
示例10: create
import android.content.pm.ResolveInfo; //导入方法依赖的package包/类
static ShareItem create(Context context, ResolveInfo resolveInfo) {
final PackageManager pm = context.getPackageManager();
final CharSequence label = resolveInfo.loadLabel(pm);
final Drawable drawable = resolveInfo.loadIcon(pm);
final ShareDescription shareDescription = new ShareDescription(drawable, label);
final ComponentName componentName = new ComponentName(
resolveInfo.activityInfo.packageName,
resolveInfo.activityInfo.name
);
return new SystemShareItem(shareDescription, componentName);
}
示例11: handleExternalUri
import android.content.pm.ResolveInfo; //导入方法依赖的package包/类
/**
* Find and open the appropriate app for a given Uri. If appropriate, let the user select between
* multiple supported apps. Returns a boolean indicating whether the URL was handled. A fallback
* URL will be opened in the supplied WebView if appropriate (in which case the URL was handled,
* and true will also be returned). If not handled, we should fall back to webviews error handling
* (which ends up calling our error handling code as needed).
*
* Note: this method "leaks" the target Uri to Android before asking the user whether they
* want to use an external app to open the uri. Ultimately the OS can spy on anything we're
* doing in the app, so this isn't an actual "bug".
*/
public static boolean handleExternalUri(final Context context, final IWebView webView, final String uri) {
// This code is largely based on Fennec's ExternalIntentDuringPrivateBrowsingPromptFragment.java
final Intent intent;
try {
intent = Intent.parseUri(uri, 0);
} catch (URISyntaxException e) {
// Let the browser handle the url (i.e. let the browser show it's unsupported protocol /
// invalid URL page).
return false;
}
// Since we're a browser:
intent.addCategory(Intent.CATEGORY_BROWSABLE);
final PackageManager packageManager = context.getPackageManager();
// This is where we "leak" the uri to the OS. If we're using the system webview, then the OS
// already knows that we're opening this uri. Even if we're using GeckoView, the OS can still
// see what domains we're visiting, so there's no loss of privacy here:
final List<ResolveInfo> matchingActivities = packageManager.queryIntentActivities(intent, 0);
if (matchingActivities.size() == 0) {
return handleUnsupportedLink(context, webView, intent);
} else if (matchingActivities.size() == 1) {
final ResolveInfo info;
if (matchingActivities.size() == 1) {
info = matchingActivities.get(0);
} else {
// Ordering isn't guaranteed if there is more than one available activity - hence
// we fetch the default (this code isn't currently run because we handle the > 1
// case separately, but would be needed if we ever decide to prefer the default
// app for the > 1 case.
info = packageManager.resolveActivity(intent, 0);
}
final CharSequence externalAppTitle = info.loadLabel(packageManager);
showConfirmationDialog(context, intent, context.getString(R.string.external_app_prompt_title), R.string.external_app_prompt, externalAppTitle);
return true;
} else { // matchingActivities.size() > 1
// By explicitly showing the chooser, we can avoid having a (default) app from opening
// the link immediately. This isn't perfect - we'd prefer to highlight the default app,
// but it's not clear if there's any way of doing that. An alternative
// would be to reuse the same dialog as for the single-activity case, and offer
// a "open in other app this time" button if we have more than one matchingActivity.
final String chooserTitle = context.getString(R.string.external_multiple_apps_matched_exit);
final Intent chooserIntent = Intent.createChooser(intent, chooserTitle);
context.startActivity(chooserIntent);
return true;
}
}
示例12: IconPackInfo
import android.content.pm.ResolveInfo; //导入方法依赖的package包/类
IconPackInfo(ResolveInfo r, PackageManager packageManager) {
packageName = r.activityInfo.packageName;
icon = r.loadIcon(packageManager);
label = r.loadLabel(packageManager);
}
示例13: getData
import android.content.pm.ResolveInfo; //导入方法依赖的package包/类
protected List<Map<String, Object>> getData(String prefix) {
List<Map<String, Object>> myData = new ArrayList<Map<String, Object>>();
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(APP_CAGEGORY);
PackageManager pm = getPackageManager();
List<ResolveInfo> list = pm.queryIntentActivities(mainIntent, 0);
if (null == list)
return myData;
String[] prefixPath;
String prefixWithSlash = prefix;
if (prefix.equals("")) {
prefixPath = null;
} else {
prefixPath = prefix.split("/");
prefixWithSlash = prefix + "/";
}
int len = list.size();
Map<String, Boolean> entries = new HashMap<String, Boolean>();
for (int i = 0; i < len; i++) {
ResolveInfo info = list.get(i);
CharSequence labelSeq = info.loadLabel(pm);
String label = labelSeq != null
? labelSeq.toString()
: info.activityInfo.name;
Log.w("yjt","labelSeq = "+labelSeq+"; label="+label+" ; prefixPath="+prefixPath+" ; prefixWithSlash="+prefixWithSlash);
if (prefixWithSlash.length() == 0 || label.startsWith(prefixWithSlash)) {
String[] labelPath = label.split("/");
String nextLabel = prefixPath == null ? labelPath[0] : labelPath[prefixPath.length];
if ((prefixPath != null ? prefixPath.length : 0) == labelPath.length - 1) {
addItem(myData, nextLabel, activityIntent(
info.activityInfo.applicationInfo.packageName,
info.activityInfo.name));
} else {
if (entries.get(nextLabel) == null) {
addItem(myData, nextLabel, browseIntent(prefix.equals("") ? nextLabel : prefix + "/" + nextLabel));
entries.put(nextLabel, true);
}
}
}
}
Collections.sort(myData, sDisplayNameComparator);
return myData;
}
示例14: getData
import android.content.pm.ResolveInfo; //导入方法依赖的package包/类
protected List<Map<String, Object>> getData(String prefix) {
List<Map<String, Object>> myData = new ArrayList<>();
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(CATEGORY_ACTIVITIES);
PackageManager pm = getPackageManager();
List<ResolveInfo> list = pm.queryIntentActivities(mainIntent, 0);
if (null == list) {
return myData;
}
String[] prefixPath;
String prefixWithSlash = prefix;
if (prefix.equals("")) {
prefixPath = null;
} else {
prefixPath = prefix.split("/");
prefixWithSlash = prefix + "/";
}
int len = list.size();
Map<String, Boolean> entries = new HashMap<>();
for (int i = 0; i < len; i++) {
ResolveInfo info = list.get(i);
CharSequence labelSeq = info.loadLabel(pm);
String label = labelSeq != null
? labelSeq.toString()
: info.activityInfo.name;
if (prefixWithSlash.length() == 0 || label.startsWith(prefixWithSlash)) {
String[] labelPath = label.split("/");
String nextLabel = prefixPath == null ? labelPath[0] : labelPath[prefixPath.length];
if ((prefixPath != null ? prefixPath.length : 0) == labelPath.length - 1) {
addItem(myData, nextLabel, activityIntent(
info.activityInfo.applicationInfo.packageName,
info.activityInfo.name));
} else {
if (entries.get(nextLabel) == null) {
addItem(myData, nextLabel, browseIntent(prefix.equals("") ? nextLabel : prefix + "/" + nextLabel));
entries.put(nextLabel, true);
}
}
}
}
Collections.sort(myData, sDisplayNameComparator);
return myData;
}
示例15: getData
import android.content.pm.ResolveInfo; //导入方法依赖的package包/类
public List<Map<String, Object>> getData(String prefix) {
List<Map<String, Object>> list = new ArrayList<>();
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_TEST);
PackageManager pm = getPackageManager();
List<ResolveInfo> infos = pm.queryIntentActivities(mainIntent, 0);
if (infos == null) return list;
String[] prefixPath;
String prefixWithSlash = prefix;
if (prefix.equals("")) {
prefixPath = null;
} else {
prefixPath = prefix.split("/");
prefixWithSlash = prefix + "/";
}
int len = infos.size();
Map<String, Boolean> entries = new HashMap<String, Boolean>();
for (int i = 0; i < len; i++) {
ResolveInfo info = infos.get(i);
CharSequence labelSeq = info.loadLabel(pm);
String label = labelSeq == null ? info.activityInfo.name : labelSeq.toString();
if(prefixWithSlash.length() == 0 || label.startsWith(prefixWithSlash)){
String[] labelPath = label.split("/");
String nextLabel = prefixPath == null ? labelPath[0] : labelPath[prefixPath.length];
if((prefixPath != null ? prefixPath.length : 0) == labelPath.length - 1){
addItem(list,nextLabel,activityIntent(
info.activityInfo.applicationInfo.packageName,
info.activityInfo.name));
}else{
if (entries.get(nextLabel) == null) {
addItem(list, nextLabel, browseIntent(prefix.equals("") ? nextLabel : prefix + "/" + nextLabel));
entries.put(nextLabel, true);
}
}
}
}
Collections.sort(list, sDisplayNameComparator);
return list;
}