Java Code Examples for android.content.pm.ResolveInfo#loadLabel()
The following examples show how to use
android.content.pm.ResolveInfo#loadLabel() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java From minimalist-launcher with GNU General Public License v2.0 | 6 votes |
private void fetchAppList() { // Start from a clean adapter when refreshing the list adapter.clear(); packageNames.clear(); // Query the package manager for all apps List<ResolveInfo> activities = packageManager.queryIntentActivities( new Intent(Intent.ACTION_MAIN, null).addCategory(Intent.CATEGORY_LAUNCHER), 0); // Sort the applications by alphabetical order and add them to the list Collections.sort(activities, new ResolveInfo.DisplayNameComparator(packageManager)); for (ResolveInfo resolver : activities) { // Exclude the settings app and this launcher from the list of apps shown String appName = (String) resolver.loadLabel(packageManager); if (appName.equals("Settings") || appName.equals("Minimalist Launcher")) continue; adapter.add(appName); packageNames.add(resolver.activityInfo.packageName); } listView.setAdapter(adapter); }
Example 2
Source File: AppNavHomeActivity.java From V.FlyoutTest with MIT License | 6 votes |
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; }
Example 3
Source File: InstalledAppsActivity.java From Light-Android-Launcher with GNU General Public License v2.0 | 6 votes |
private void fetchAppList() { PackageManager packageManager = getPackageManager(); List<ResolveInfo> activities = getActivities(packageManager); lock.writeLock().lock(); appsPosition.clear(); adapter.clear(); for (ResolveInfo resolver : activities) { String appName = (String) resolver.loadLabel(packageManager); if (appName.equals("Light Android Launcher")) continue; adapter.add(appName); appsPosition.add(Pair.create(appName, resolver.activityInfo.packageName)); } listView.setBackgroundColor(getResources().getColor(R.color.colorBackgroundPrimary)); setActions(); lock.writeLock().unlock(); }
Example 4
Source File: AppManager.java From shadowsocks-android-java with Apache License 2.0 | 6 votes |
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); } } }
Example 5
Source File: PageApp.java From TvLauncher with Apache License 2.0 | 6 votes |
public AppInfoVo getApp(ResolveInfo app) { AppInfoVo mAppInfo = new AppInfoVo(); mAppInfo.mAppName = (String) app.loadLabel(mPackManager); mAppInfo.mAppPackageName = app.activityInfo.packageName; mAppInfo.mAppIcon = app.loadIcon(mPackManager); if ((app.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { mAppInfo.isSystemApps = true; } else { mAppInfo.isSystemApps = false; } Intent intent = new Intent(); intent.setComponent(new ComponentName(app.activityInfo.packageName, app.activityInfo.name)); mAppInfo.mAppIntent = intent; return mAppInfo; }
Example 6
Source File: ActivityChooserView.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * 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==1 || activityCount > 1 && 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); } } else { mDefaultActivityButton.setVisibility(View.GONE); } // Activity chooser content. if (mDefaultActivityButton.getVisibility() == VISIBLE) { mActivityChooserContent.setBackground(mActivityChooserContentBackground); } else { mActivityChooserContent.setBackground(null); } }
Example 7
Source File: AppItem.java From timecat with Apache License 2.0 | 5 votes |
@Override public CharSequence getDisplayName() { if (mDisplayName != null) { return mDisplayName; } ResolveInfo ri = getResolveInfo(); if (ri != null) { return mDisplayName = ri.loadLabel(mContext.getPackageManager()); } return null; }
Example 8
Source File: AppInfoProvider.java From apollo-DuerOS with Apache License 2.0 | 5 votes |
public AppInfo getSingleInfo(ResolveInfo reInfo, String packageFilter) { String pkgName = reInfo.activityInfo.packageName; // Get the package name of the application AppInfo appInfo = null; if (TextUtils.equals(pkgName, packageFilter) || TextUtils.equals(APP_NO_FILTER, packageFilter)) { String activityName = reInfo.activityInfo.name; // Get the name of the startup Activity for the application String appLabel = (String) reInfo.loadLabel(mPackageManager); // Get the application Label Drawable icon = reInfo.loadIcon(mPackageManager); // Get the application icon // Preparing Intent for application startup Activity Intent launchIntent = new Intent(); launchIntent.setComponent(new ComponentName(pkgName, activityName)); // create an AppInfo appInfo = new AppInfo(); appInfo.setPackageName(pkgName); appInfo.setAppName(appLabel); appInfo.setIcon(icon); appInfo.setActivityName(activityName); appInfo.setIntent(launchIntent); try { PackageInfo mPackageInfo = mContext.getPackageManager().getPackageInfo(pkgName, 0); if ((mPackageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) <= 0) { // third apps appInfo.setSystem(false); } else { // system apps appInfo.setSystem(true); } } catch (PackageManager.NameNotFoundException e) { LogUtil.e("AppInfoProvider", e.getMessage().toString()); } } return appInfo; }
Example 9
Source File: ActivityChooserView.java From android-apps with MIT License | 5 votes |
/** * 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); } } else { mDefaultActivityButton.setVisibility(View.GONE); } // Activity chooser content. if (mDefaultActivityButton.getVisibility() == VISIBLE) { mActivityChooserContent.setBackgroundDrawable(mActivityChooserContentBackground); } else { mActivityChooserContent.setBackgroundDrawable(null); } }
Example 10
Source File: MainActivity.java From android-openGL-canvas with Apache License 2.0 | 4 votes |
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; }
Example 11
Source File: ListSamples.java From android-open-project-demo with Apache License 2.0 | 4 votes |
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("com.jakewharton.android.viewpagerindicator.sample.SAMPLE"); 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; 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, NAME_COMPARATOR); return myData; }
Example 12
Source File: IconPackHelper.java From Hangar with GNU General Public License v3.0 | 4 votes |
IconPackInfo(ResolveInfo r, PackageManager packageManager) { packageName = r.activityInfo.packageName; icon = r.loadIcon(packageManager); label = r.loadLabel(packageManager); }
Example 13
Source File: WheelDemo.java From BigApp_Discuz_Android with Apache License 2.0 | 4 votes |
protected List getData(String prefix) { List<Map> myData = new ArrayList<Map>(); Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); mainIntent.addCategory("com.kit.widget.wheel.WHEEL_SAMPLE"); PackageManager pm = getPackageManager(); List<ResolveInfo> list = pm.queryIntentActivities(mainIntent, 0); if (null == list) return myData; String[] prefixPath; if (prefix.equals("")) { prefixPath = null; } else { prefixPath = prefix.split("/"); } 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; if (prefix.length() == 0 || label.startsWith(prefix)) { 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; }
Example 14
Source File: MainActivity.java From AndroidInstantVideo with Apache License 2.0 | 4 votes |
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; }
Example 15
Source File: HomeActivity.java From AndroidUiKit with Apache License 2.0 | 4 votes |
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; }
Example 16
Source File: IconPackPreference.java From LaunchEnr with GNU General Public License v3.0 | 4 votes |
IconPackInfo(ResolveInfo r, PackageManager packageManager) { packageName = r.activityInfo.packageName; icon = r.loadIcon(packageManager); label = r.loadLabel(packageManager); }
Example 17
Source File: IconsManager.java From LaunchEnr with GNU General Public License v3.0 | 4 votes |
IconPackInfo(ResolveInfo r, PackageManager packageManager) { packageName = r.activityInfo.packageName; icon = r.loadIcon(packageManager); label = r.loadLabel(packageManager); }
Example 18
Source File: ObservableScrollViewActivity.java From UltimateAndroid with Apache License 2.0 | 4 votes |
private List<Map<String, Object>> getData() { List<Map<String, Object>> data = new ArrayList<Map<String, Object>>(); Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); mainIntent.addCategory(CATEGORY_SAMPLES); PackageManager pm = getPackageManager(); List<ResolveInfo> list = pm.queryIntentActivities(mainIntent, 0); Logs.d("observable-----" + (list == null)); if (list == null) { return data; } for (ResolveInfo info : list) { CharSequence labelSeq = info.loadLabel(pm); String label = labelSeq != null ? labelSeq.toString() : info.activityInfo.name; String[] labelPath = label.split("/"); String nextLabel = labelPath[0]; if (labelPath.length == 1) { String nameLabel = info.activityInfo.name.replace(info.activityInfo.packageName + "", ""); // Remove package and get simple class name if (nameLabel.contains(".")) { nameLabel = nameLabel.replaceAll("[^.]*\\.", ""); } addItem(data, nameLabel, nextLabel, activityIntent( info.activityInfo.applicationInfo.packageName, info.activityInfo.name)); } } Collections.sort(data, DISPLAY_NAME_COMPARATOR); Logs.d("data------" + data.size()); return data; }
Example 19
Source File: MainActivity.java From SimpleAlertDialog-for-Android with Apache License 2.0 | 4 votes |
private List<Map<String, Object>> getData() { List<Map<String, Object>> data = new ArrayList<Map<String, Object>>(); Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); mainIntent.addCategory("com.simplealertdialog.sample.demos"); if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) { mainIntent.addCategory("com.simplealertdialog.sample.demos.gingerbread"); } PackageManager pm = getPackageManager(); List<ResolveInfo> list = pm.queryIntentActivities(mainIntent, 0); if (list == null) { return data; } int len = list.size(); 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; String[] labelPath = label.split("/"); String nextLabel = labelPath[0]; if (labelPath.length == 1) { addItem(data, info.activityInfo.name.replace(info.activityInfo.packageName + "", ""), nextLabel, activityIntent( info.activityInfo.applicationInfo.packageName, info.activityInfo.name)); } } Collections.sort(data, DISPLAY_NAME_COMPARATOR); return data; }
Example 20
Source File: ApiDemos.java From codeexamples-android with Eclipse Public License 1.0 | 4 votes |
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(Intent.CATEGORY_SAMPLE_CODE); 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; 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; }