List of usage examples for android.content.pm ActivityInfo loadLabel
public @NonNull CharSequence loadLabel(@NonNull PackageManager pm)
From source file:com.ddj.launcher2.InstallShortcutReceiver.java
public void onReceive(Context context, Intent data) { if (!ACTION_INSTALL_SHORTCUT.equals(data.getAction())) { return;/*from w w w. java 2 s. c o m*/ } Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT); if (intent == null) { return; } // This name is only used for comparisons and notifications, so fall back to activity name // if not supplied String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME); if (name == null) { try { PackageManager pm = context.getPackageManager(); ActivityInfo info = pm.getActivityInfo(intent.getComponent(), 0); name = info.loadLabel(pm).toString(); } catch (PackageManager.NameNotFoundException nnfe) { return; } } Bitmap icon = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON); Intent.ShortcutIconResource iconResource = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE); // Queue the item up for adding if launcher has not loaded properly yet boolean launcherNotLoaded = LauncherModel.getCellCountX() <= 0 || LauncherModel.getCellCountY() <= 0; PendingInstallShortcutInfo info = new PendingInstallShortcutInfo(data, name, intent); info.icon = icon; info.iconResource = iconResource; if (mUseInstallQueue || launcherNotLoaded) { String spKey = LauncherUtil.getSharedPreferencesKey(); SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE); addToInstallQueue(sp, info); } else { processInstallShortcut(context, info); } }
From source file:eu.inmite.apps.smsjizdenka.activity.MainActivity.java
private void checkForHigherPriorityReceivers() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT && Preferences.getBoolean(c, Preferences.PRIORITY_DIALOG_ENABLED, true)) { final Intent intent = new Intent("android.provider.Telephony.SMS_RECEIVED"); final List<ResolveInfo> activities = getPackageManager().queryBroadcastReceivers(intent, 0); for (ResolveInfo resolveInfo : activities) { ActivityInfo activityInfo = resolveInfo.activityInfo; if (activityInfo != null) { // skip avast if (activityInfo.name.startsWith("com.avast.android")) { continue; }/*from ww w .j a v a2s .c o m*/ if (!activityInfo.name.startsWith("eu.inmite.apps.smsjizdenka")) { String appName = activityInfo.loadLabel(getPackageManager()).toString(); //SL.get(AnalyticsService.class).trackEvent("higher-priority-receiver", "on-start", "app-name", appName); IncompatibleDialogFragment.newInstance(appName).show(getSupportFragmentManager(), MessageDialogFragment.TAG); } break; } } Preferences.set(c, Preferences.PRIORITY_DIALOG_ENABLED, false); } }
From source file:uk.co.ashtonbrsc.intentexplode.Explode.java
private void checkAndShowMatchingActivites() { activitiesLayout.removeAllViews();// w w w.j a v a 2 s .c o m PackageManager pm = getPackageManager(); List<ResolveInfo> resolveInfo = pm.queryIntentActivities(editableIntent, 0); // Remove Intent Intercept from matching activities int numberOfMatchingActivities = resolveInfo.size() - 1; if (numberOfMatchingActivities < 1) { resendIntentButton.setEnabled(false); activitiesHeader.setText(getResources().getString(R.string.no_activities_match_intent)); } else { resendIntentButton.setEnabled(true); activitiesHeader.setText(getResources().getQuantityString(R.plurals.activities_match_intent, numberOfMatchingActivities, numberOfMatchingActivities)); for (int i = 0; i <= numberOfMatchingActivities; i++) { ResolveInfo info = resolveInfo.get(i); ActivityInfo activityinfo = info.activityInfo; if (!activityinfo.packageName.equals(getPackageName())) { addTextToLayout( activityinfo.loadLabel(pm) + getResources().getString(R.string.open_bracket) + activityinfo.packageName + getResources().getString(R.string.dash) + activityinfo.name + getResources().getString(R.string.close_bracket), Typeface.NORMAL, activitiesLayout); } } } }
From source file:uk.co.ashtonbrsc.intentexplode.Explode.java
private Spanned getIntentDetailsString() { // TODO make sure this has all // the details StringBuilder stringBuilder = new StringBuilder(); // k3b so intent can be reloaded using // Intent.parseUri("Intent:....", Intent.URI_INTENT_SCHEME) stringBuilder.append(getUri(editableIntent)).append(NEWLINE); // support for onActivityResult if (this.lastResultCode != null) { stringBuilder.append(getResources().getString(R.string.last_result)) .append(this.lastResultCode.toString()); if (this.lastResultIntent != null) { stringBuilder.append(getResources().getString(R.string.data)).append(lastResultIntent); }//from w ww . ja va 2 s. c o m stringBuilder.append(NEWLINE); } stringBuilder.append(NEWLINE).append(getResources().getString(R.string.action_bold)) .append(editableIntent.getAction()).append(NEWLINE); stringBuilder.append(getResources().getString(R.string.data_bold)).append(editableIntent.getData()) .append(NEWLINE); stringBuilder.append(getResources().getString(R.string.type_bold)).append(editableIntent.getType()) .append(NEWLINE); Set<String> categories = editableIntent.getCategories(); if (categories != null) { stringBuilder.append(getResources().getString(R.string.categories_title_bold)); for (String category : categories) { stringBuilder.append(category).append(NEWLINE); } } stringBuilder.append(getResources().getString(R.string.flags_title_bold)); ArrayList<String> flagsStrings = getFlags(); if (!flagsStrings.isEmpty()) { for (String thisFlagString : flagsStrings) { stringBuilder.append(thisFlagString).append(NEWLINE); } } else { stringBuilder.append(getResources().getString(R.string.none)).append(NEWLINE); } try { Bundle intentBundle = editableIntent.getExtras(); if (intentBundle != null) { Set<String> keySet = intentBundle.keySet(); stringBuilder.append(getResources().getString(R.string.extras_title_bold)); int count = 0; for (String key : keySet) { count++; Object thisObject = intentBundle.get(key); stringBuilder.append(getResources().getQuantityString(R.plurals.extra_count, count, count)); String thisClass = thisObject.getClass().getName(); if (thisClass != null) { stringBuilder.append(getResources().getString(R.string.class_text)).append(thisClass) .append(NEWLINE); } stringBuilder.append(getResources().getString(R.string.key)).append(key).append(NEWLINE); if (thisObject instanceof String || thisObject instanceof Long || thisObject instanceof Integer || thisObject instanceof Boolean || thisObject instanceof Uri) { stringBuilder.append(getResources().getString(R.string.value)).append(thisObject.toString()) .append(NEWLINE); } else if (thisObject instanceof ArrayList) { stringBuilder.append(getResources().getString(R.string.values_break)); ArrayList thisArrayList = (ArrayList) thisObject; for (Object thisArrayListObject : thisArrayList) { stringBuilder.append(thisArrayListObject.toString()).append(NEWLINE); } } } } } catch (Exception e) { stringBuilder.append(getResources().getString(R.string.bundle_title_bold_uppercase)); stringBuilder.append(getResources().getString(R.string.error_extracting_extras_red)); e.printStackTrace(); } PackageManager pm = getPackageManager(); List<ResolveInfo> resolveInfo = pm.queryIntentActivities(editableIntent, 0); // Remove Intent Intercept from matching activities int numberOfMatchingActivities = resolveInfo.size() - 1; if (numberOfMatchingActivities < 1) { stringBuilder.append(getResources().getString(R.string.no_activities_match_intent_title_bold)); } else { stringBuilder.append(getResources().getQuantityString(R.plurals.activites_match_intent_title_bold, numberOfMatchingActivities, numberOfMatchingActivities)); for (int i = 0; i <= numberOfMatchingActivities; i++) { ResolveInfo info = resolveInfo.get(i); ActivityInfo activityinfo = info.activityInfo; if (!activityinfo.packageName.equals(getPackageName())) { stringBuilder.append(activityinfo.loadLabel(pm)) .append(getResources().getString(R.string.open_bracket)) .append(activityinfo.packageName).append(getResources().getString(R.string.dash)) .append(activityinfo.name) .append(getResources().getString(R.string.close_bracket_break)); } } } return Html.fromHtml(stringBuilder.toString()); }
From source file:com.actionbarsherlock.internal.app.ActionBarHandlerWatson.java
@Override protected void performAttach() { getActivity().requestWindowFeature(Window.FEATURE_NO_TITLE); setActivityContentView(R.layout.actionbarwatson_wrapper); mActionBar = (ActionBarWatson) getActivity().findViewById(R.id.actionbarwatson); mContentView = (FrameLayout) getActivity().findViewById(R.id.actionbarsherlock_content); final MenuItemImpl homeMenuItem = getHomeMenuItem(); final ActionBarWatson.Item homeItem = mActionBar.getHomeItem(); final WatsonItemViewWrapper homeWrapper = new WatsonItemViewWrapper(homeItem); homeWrapper.initialize(homeMenuItem, MenuBuilder.TYPE_WATSON); homeMenuItem.setItemView(MenuBuilder.TYPE_WATSON, homeWrapper); final PackageManager pm = getActivity().getPackageManager(); final ApplicationInfo appInfo = getActivity().getApplicationInfo(); ActivityInfo actInfo = null; try {// ww w . j a va 2s . com actInfo = pm.getActivityInfo(getActivity().getComponentName(), PackageManager.GET_ACTIVITIES); } catch (NameNotFoundException e) { } if ((actInfo != null) && (actInfo.labelRes != 0)) { //Load label string resource from the activity entry mActionBar.setTitle(actInfo.labelRes); } else if (mActionBar.getTitle() == null) { //No activity label string resource and none in theme mActionBar.setTitle(actInfo.loadLabel(pm)); } if ((actInfo != null) && (actInfo.icon != 0)) { //Load the icon from the activity entry homeItem.setIcon(actInfo.icon); } else if (homeItem.getIcon() == null) { //No activity icon and none in theme homeItem.setIcon(pm.getApplicationIcon(appInfo)); } //XXX LOGO LOADING DOES NOT WORK //XXX SEE: http://stackoverflow.com/questions/6105504/load-activity-and-or-application-logo-programmatically-from-manifest //XXX SEE: https://groups.google.com/forum/#!topic/android-developers/UFR4l0ZwJWc //if ((actInfo != null) && (actInfo.logo != 0)) { // //Load the logo from the activity entry // homeItem.setLogo(actInfo.logo); //} else if ((homeItem.getLogo() == null) && (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD)) { // //No activity logo and none in theme // homeItem.setLogo(appInfo.logo); //} }
From source file:de.ub0r.android.smsdroid.MessageListActivity.java
/** * {@inheritDoc}// ww w. j a v a2s. c om */ @Override protected final void onResume() { super.onResume(); boolean noAds = DonationHelper.hideAds(this); if (!noAds) { Ads.loadAd(this, R.id.ad, ADMOB_PUBID, AD_KEYWORDS); } final ListView lv = this.getListView(); lv.setTranscriptMode(AbsListView.TRANSCRIPT_MODE_ALWAYS_SCROLL); lv.setAdapter(new MessageAdapter(this, this.uri)); this.markedUnread = false; final Button btn = (Button) this.findViewById(R.id.send_); if (this.showTextField) { final Intent i = this.buildIntent(this.enableAutosend, false); final PackageManager pm = this.getPackageManager(); ActivityInfo ai = null; if (PreferenceManager.getDefaultSharedPreferences(this) .getBoolean(PreferencesActivity.PREFS_SHOWTARGETAPP, true)) { ai = i.resolveActivityInfo(pm, 0); } if (ai == null) { btn.setText(null); this.etText.setMinLines(1); } else { if (chooserPackage == null) { final ActivityInfo cai = this.buildIntent(this.enableAutosend, true).resolveActivityInfo(pm, 0); if (cai != null) { chooserPackage = cai.packageName; } } if (ai.packageName.equals(chooserPackage)) { btn.setText(R.string.chooser_); } else { Log.d(TAG, "ai.pn: " + ai.packageName); btn.setText(ai.loadLabel(pm)); } this.etText.setMinLines(3); } } else { btn.setText(null); } }
From source file:com.android.settings.HWSettings.java
/** * Switch to parent fragment and store the grand parent's info * @param className name of the activity wrapper for the parent fragment. */// w w w. ja v a 2s . c om 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(LOG_TAG, "Could not find parent activity : " + className); } }
From source file:com.cognizant.trumobi.PersonaLauncher.java
private static PersonaApplicationInfo infoFromApplicationIntent(Context context, Intent data) { ComponentName component = data.getComponent(); PackageManager packageManager = context.getPackageManager(); ActivityInfo activityInfo = null; try {/*from w ww . ja va2 s . c o m*/ activityInfo = packageManager.getActivityInfo(component, 0 /* * no * flags */); } catch (NameNotFoundException e) { PersonaLog.e(LOG_TAG, "Couldn't find ActivityInfo for selected application", e); } if (activityInfo != null) { PersonaApplicationInfo itemInfo = new PersonaApplicationInfo(); itemInfo.title = activityInfo.loadLabel(packageManager); if (itemInfo.title == null) { itemInfo.title = activityInfo.name; } itemInfo.setActivity(component, Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); // itemInfo.icon = activityInfo.loadIcon(packageManager); itemInfo.container = PersonaItemInfo.NO_ID; itemInfo.icon = PersonaLauncherModel.getIcon(packageManager, context, activityInfo); return itemInfo; } return null; }