Java Code Examples for android.content.pm.ActivityInfo#loadLabel()
The following examples show how to use
android.content.pm.ActivityInfo#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: WeChatDecoratorSettingsActivity.java From decorator-wechat with Apache License 2.0 | 6 votes |
private boolean selectAgentLabel() { final PackageManager pm = getPackageManager(); final Intent query = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER).setPackage(AGENT_WECHAT_PACKAGE); final List<ResolveInfo> resolves = pm.queryIntentActivities(query, PackageManager.GET_DISABLED_COMPONENTS); final int size = resolves.size(); if (size <= 1) throw new IllegalStateException("No activities found for " + query); final CharSequence[] labels = new CharSequence[size + 1]; final String[] names = new String[size]; for (int i = 0; i < size; i ++) { final ActivityInfo activity = resolves.get(i).activityInfo; labels[i] = activity.loadLabel(pm); names[i] = activity.name; } labels[size] = getText(R.string.action_disable_agent_launcher_entrance); new AlertDialog.Builder(this).setSingleChoiceItems(labels, -1, (dialog, which) -> { // TODO: Item cannot be selected on Sony device? for (int i = 0; i < names.length; i ++) pm.setComponentEnabledSetting(new ComponentName(AGENT_WECHAT_PACKAGE, names[i]), i == which ? COMPONENT_ENABLED_STATE_ENABLED : COMPONENT_ENABLED_STATE_DISABLED, DONT_KILL_APP); dialog.dismiss(); }).show(); return true; }
Example 2
Source File: Theme.java From CSipSimple with GNU General Public License v3.0 | 6 votes |
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; }
Example 3
Source File: PurgeableBitmap.java From codeexamples-android with Eclipse Public License 1.0 | 6 votes |
private boolean detectIfPurgeableRequest() { PackageManager pm = getPackageManager(); CharSequence labelSeq = null; try { ActivityInfo info = pm.getActivityInfo(this.getComponentName(), PackageManager.GET_META_DATA); labelSeq = info.loadLabel(pm); } catch (NameNotFoundException e) { e.printStackTrace(); return false; } String[] components = labelSeq.toString().split("/"); if (components[components.length - 1].equals("Purgeable")) { return true; } else { return false; } }
Example 4
Source File: InstallShortcutReceiver.java From LaunchEnr with GNU General Public License v3.0 | 5 votes |
/** * Ensures that we have a valid, non-null name. If the provided name is null, we will return * the application name instead. */ @Thunk static CharSequence ensureValidName(Context context, Intent intent, CharSequence name) { if (name == null) { try { PackageManager pm = context.getPackageManager(); ActivityInfo info = pm.getActivityInfo(intent.getComponent(), 0); name = info.loadLabel(pm); } catch (PackageManager.NameNotFoundException nnfe) { return ""; } } return name; }
Example 5
Source File: SetupViewModel.java From island with Apache License 2.0 | 5 votes |
private static CharSequence readOwnerLabel(final Context context, final ComponentName owner) { final PackageManager pm = context.getPackageManager(); try { final ActivityInfo owner_info = pm.getReceiverInfo(owner, 0); // It should be a BroadcastReceiver if (owner_info != null) return owner_info.loadLabel(pm); return pm.getApplicationInfo(owner.getPackageName(), 0).loadLabel(pm); // If not, use app label } catch (final PackageManager.NameNotFoundException ignored) { return null; } }
Example 6
Source File: InstallShortcutReceiver.java From Trebuchet with GNU General Public License v3.0 | 5 votes |
/** * Ensures that we have a valid, non-null name. If the provided name is null, we will return * the application name instead. */ @Thunk static CharSequence ensureValidName(Context context, Intent intent, CharSequence name) { if (name == null) { try { PackageManager pm = context.getPackageManager(); ActivityInfo info = pm.getActivityInfo(intent.getComponent(), 0); name = info.loadLabel(pm); } catch (PackageManager.NameNotFoundException nnfe) { return ""; } } return name; }
Example 7
Source File: BlacklistActivity.java From AcDisplay with GNU General Public License v2.0 | 5 votes |
/** * Switch to parent fragment and store the grand parent's info * * @param className name of the activity wrapper for the parent fragment. */ private void switchToParent(String className) { final ComponentName cn = new ComponentName(this, className); try { final PackageManager pm = getPackageManager(); final ActivityInfo parentInfo = pm.getActivityInfo(cn, PackageManager.GET_META_DATA); if (parentInfo != null && parentInfo.metaData != null) { String fragmentClass = parentInfo.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS); CharSequence fragmentTitle = parentInfo.loadLabel(pm); Header parentHeader = new Header(); parentHeader.fragment = fragmentClass; parentHeader.title = fragmentTitle; mCurrentHeader = parentHeader; switchToHeaderLocal(parentHeader); highlightHeader(mTopLevelHeaderId); mParentHeader = new Header(); mParentHeader.fragment = parentInfo.metaData.getString(META_DATA_KEY_PARENT_FRAGMENT_CLASS); mParentHeader.title = parentInfo.metaData.getString(META_DATA_KEY_PARENT_TITLE); } } catch (NameNotFoundException nnfe) { Log.w(TAG, "Could not find parent activity : " + className); } }
Example 8
Source File: AdvancedShareActionProvider.java From Android-Next with Apache License 2.0 | 5 votes |
/** * 根据ResolveInfo生成ShareTarget * * @param resolveInfo ResolveInfo * @return ShareTarget */ private ShareTarget toShareTarget(ResolveInfo resolveInfo) { if (resolveInfo == null || resolveInfo.activityInfo == null) { return null; } ActivityInfo info = resolveInfo.activityInfo; ShareTarget target = new ShareTarget(info.loadLabel(mPackageManager), info.loadIcon(mPackageManager), null); target.packageName = info.packageName; target.className = info.name; return target; }
Example 9
Source File: AdvancedShareActionProvider.java From Android-Next with Apache License 2.0 | 5 votes |
/** * 根据ResolveInfo生成ShareTarget * * @param resolveInfo ResolveInfo * @return ShareTarget */ private ShareTarget toShareTarget(ResolveInfo resolveInfo) { if (resolveInfo == null || resolveInfo.activityInfo == null) { return null; } ActivityInfo info = resolveInfo.activityInfo; ShareTarget target = new ShareTarget(info.loadLabel(mPackageManager), info.loadIcon(mPackageManager), null); target.packageName = info.packageName; target.className = info.name; return target; }
Example 10
Source File: BlacklistActivity.java From HeadsUp with GNU General Public License v2.0 | 5 votes |
/** * Switch to parent fragment and store the grand parent's info * * @param className name of the activity wrapper for the parent fragment. */ private void switchToParent(String className) { final ComponentName cn = new ComponentName(this, className); try { final PackageManager pm = getPackageManager(); final ActivityInfo parentInfo = pm.getActivityInfo(cn, PackageManager.GET_META_DATA); if (parentInfo != null && parentInfo.metaData != null) { String fragmentClass = parentInfo.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS); CharSequence fragmentTitle = parentInfo.loadLabel(pm); Header parentHeader = new Header(); parentHeader.fragment = fragmentClass; parentHeader.title = fragmentTitle; mCurrentHeader = parentHeader; switchToHeaderLocal(parentHeader); highlightHeader(mTopLevelHeaderId); mParentHeader = new Header(); mParentHeader.fragment = parentInfo.metaData.getString(META_DATA_KEY_PARENT_FRAGMENT_CLASS); mParentHeader.title = parentInfo.metaData.getString(META_DATA_KEY_PARENT_TITLE); } } catch (NameNotFoundException nnfe) { Log.w(TAG, "Could not find parent activity : " + className); } }