List of usage examples for android.content.pm PackageManager GET_META_DATA
int GET_META_DATA
To view the source code for android.content.pm PackageManager GET_META_DATA.
Click Source Link
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. *///from w w w . ja va 2s . c o m 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.hippo.content.FileProvider.java
/** * Parse and return {@link PathStrategy} for given authority as defined in * {@link #META_DATA_FILE_PROVIDER_PATHS} {@code <meta-data>}. * * @see #getPathStrategy(Context, String) *//* ww w . j a va 2 s . c o m*/ private static PathStrategy parsePathStrategy(Context context, String authority) throws IOException, XmlPullParserException { final SimplePathStrategy strat = new SimplePathStrategy(authority); final ProviderInfo info = context.getPackageManager().resolveContentProvider(authority, PackageManager.GET_META_DATA); final XmlResourceParser in = info.loadXmlMetaData(context.getPackageManager(), META_DATA_FILE_PROVIDER_PATHS); if (in == null) { throw new IllegalArgumentException("Missing " + META_DATA_FILE_PROVIDER_PATHS + " meta-data"); } int type; while ((type = in.next()) != END_DOCUMENT) { if (type == START_TAG) { final String tag = in.getName(); final String name = in.getAttributeValue(null, ATTR_NAME); String path = in.getAttributeValue(null, ATTR_PATH); File target = null; if (TAG_ROOT_PATH.equals(tag)) { target = DEVICE_ROOT; } else if (TAG_FILES_PATH.equals(tag)) { target = context.getFilesDir(); } else if (TAG_CACHE_PATH.equals(tag)) { target = context.getCacheDir(); } else if (TAG_EXTERNAL.equals(tag)) { target = Environment.getExternalStorageDirectory(); } else if (TAG_EXTERNAL_FILES.equals(tag)) { File[] externalFilesDirs = ContextCompat.getExternalFilesDirs(context, null); if (externalFilesDirs.length > 0) { target = externalFilesDirs[0]; } } else if (TAG_EXTERNAL_CACHE.equals(tag)) { File[] externalCacheDirs = ContextCompat.getExternalCacheDirs(context); if (externalCacheDirs.length > 0) { target = externalCacheDirs[0]; } } if (target != null) { strat.addRoot(name, buildPath(target, path)); } } } return strat; }
From source file:androidx.media.MediaSession2ImplBase.java
private static String getServiceName(Context context, String serviceAction, String id) { PackageManager manager = context.getPackageManager(); Intent serviceIntent = new Intent(serviceAction); serviceIntent.setPackage(context.getPackageName()); List<ResolveInfo> services = manager.queryIntentServices(serviceIntent, PackageManager.GET_META_DATA); String serviceName = null;//from w w w. ja v a2 s. c o m if (services != null) { for (int i = 0; i < services.size(); i++) { String serviceId = SessionToken2.getSessionId(services.get(i)); if (serviceId != null && TextUtils.equals(id, serviceId)) { if (services.get(i).serviceInfo == null) { continue; } if (serviceName != null) { throw new IllegalArgumentException( "Ambiguous session type. Multiple" + " session services define the same id=" + id); } serviceName = services.get(i).serviceInfo.name; } } } return serviceName; }
From source file:com.gmail.boiledorange73.ut.map.MapActivityBase.java
/** * (LOCAL) Gets the version name./*w ww .ja v a2 s . c o m*/ */ private String getVersionName() { PackageInfo info = null; try { info = this.getPackageManager().getPackageInfo(this.getPackageName(), PackageManager.GET_META_DATA); } catch (NameNotFoundException e) { e.printStackTrace(); } return info != null ? info.versionName : null; }
From source file:org.sipdroid.sipua.ui.Receiver.java
static Intent createHomeDockIntent() { Intent intent = new Intent(Intent.ACTION_MAIN, null); if (docked == EXTRA_DOCK_STATE_CAR) { intent.addCategory(CATEGORY_CAR_DOCK); } else if (docked == EXTRA_DOCK_STATE_DESK) { intent.addCategory(CATEGORY_DESK_DOCK); } else {//from w w w . j ava2 s . com return null; } ActivityInfo ai = intent.resolveActivityInfo(mContext.getPackageManager(), PackageManager.GET_META_DATA); if (ai == null) { return null; } if (ai.metaData != null && ai.metaData.getBoolean(METADATA_DOCK_HOME)) { intent.setClassName(ai.packageName, ai.name); return intent; } return null; }
From source file:com.googlecode.android_scripting.facade.AndroidFacade.java
@Rpc(description = "Returns package version code.") public int getPackageVersionCode(@RpcParameter(name = "packageName") final String packageName) { int result = -1; PackageInfo pInfo = null;//www.j a va 2s. c o m try { pInfo = mService.getPackageManager().getPackageInfo(packageName, PackageManager.GET_META_DATA); } catch (NameNotFoundException e) { pInfo = null; } if (pInfo != null) { result = pInfo.versionCode; } return result; }
From source file:org.getlantern.firetweet.util.Utils.java
public static void addIntentToMenuForExtension(final Context context, final Menu menu, final int groupId, final String action, final String parelableKey, final String parelableJSONKey, final FiretweetParcelable parcelable) { if (context == null || menu == null || action == null || parelableKey == null || parcelable == null) return;/*w w w .jav a2 s.c o m*/ final PackageManager pm = context.getPackageManager(); final Resources res = context.getResources(); final float density = res.getDisplayMetrics().density; final int padding = Math.round(density * 4); final Intent queryIntent = new Intent(action); queryIntent.setExtrasClassLoader(context.getClassLoader()); final List<ResolveInfo> activities = pm.queryIntentActivities(queryIntent, PackageManager.GET_META_DATA); for (final ResolveInfo info : activities) { final Intent intent = new Intent(queryIntent); if (isExtensionUseJSON(info)) { intent.putExtra(parelableJSONKey, JSONSerializer.toJSONObjectString(parcelable)); } else { intent.putExtra(parelableKey, parcelable); } intent.setClassName(info.activityInfo.packageName, info.activityInfo.name); final MenuItem item = menu.add(groupId, Menu.NONE, Menu.NONE, info.loadLabel(pm)); item.setIntent(intent); final Drawable metaDataDrawable = getMetadataDrawable(pm, info.activityInfo, METADATA_KEY_EXTENSION_ICON); final int actionIconColor = ThemeUtils.getThemeForegroundColor(context); if (metaDataDrawable != null) { metaDataDrawable.mutate(); metaDataDrawable.setColorFilter(actionIconColor, Mode.SRC_ATOP); item.setIcon(metaDataDrawable); } else { final Drawable icon = info.loadIcon(pm); final int iw = icon.getIntrinsicWidth(), ih = icon.getIntrinsicHeight(); if (iw > 0 && ih > 0) { final Drawable iconWithPadding = new PaddingDrawable(icon, padding); iconWithPadding.setBounds(0, 0, iw, ih); item.setIcon(iconWithPadding); } else { item.setIcon(icon); } } } }
From source file:com.googlecode.android_scripting.facade.AndroidFacade.java
@Rpc(description = "Returns package version name.") public String getPackageVersion(@RpcParameter(name = "packageName") final String packageName) { PackageInfo packageInfo = null;/*from ww w .j a v a2 s . co m*/ try { packageInfo = mService.getPackageManager().getPackageInfo(packageName, PackageManager.GET_META_DATA); } catch (NameNotFoundException e) { return null; } if (packageInfo != null) { return packageInfo.versionName; } return null; }
From source file:com.google.android.apps.mytracks.TrackDetailActivity.java
/** * Returns true if Google Earth app is installed. *///from w w w .jav a 2 s.co m private boolean isMapsInstalled() { try { getPackageManager().getActivityInfo(Constants.MAPS_COMPONENT, PackageManager.GET_META_DATA); return true; } catch (NameNotFoundException nnfe) { return false; } }
From source file:com.sentaroh.android.TextFileBrowser.MainActivity.java
public String getApplVersionName() { try {//from w ww . j ava2 s .co m String packegeName = getPackageName(); PackageInfo packageInfo = getPackageManager().getPackageInfo(packegeName, PackageManager.GET_META_DATA); return packageInfo.versionName; } catch (NameNotFoundException e) { return ""; } }