List of usage examples for android.content.pm PackageManager getApplicationInfo
public abstract ApplicationInfo getApplicationInfo(String packageName, @ApplicationInfoFlags int flags) throws NameNotFoundException;
From source file:com.google.android.gms.common.zze.java
public static String zzao(Context context) { Object obj = context.getApplicationInfo().name; if (!TextUtils.isEmpty(obj)) { return obj; }/* w ww . jav a 2s . c om*/ ApplicationInfo applicationInfo; String packageName = context.getPackageName(); PackageManager packageManager = context.getApplicationContext().getPackageManager(); try { applicationInfo = packageManager.getApplicationInfo(context.getPackageName(), GOOGLE_PLAY_SERVICES_VERSION_CODE); } catch (NameNotFoundException e) { applicationInfo = null; } return applicationInfo != null ? packageManager.getApplicationLabel(applicationInfo).toString() : packageName; }
From source file:cn.whereyougo.framework.utils.PackageManagerUtil.java
/** * ?AndroidManifestmeta-data/*from ww w. j ava 2 s. c o m*/ * * @return ??() */ public static String getStringMetaData(Context ctx, String key) { if (ctx == null || TextUtils.isEmpty(key)) { return null; } String resultData = null; try { PackageManager packageManager = ctx.getPackageManager(); if (packageManager != null) { ApplicationInfo applicationInfo = packageManager.getApplicationInfo(ctx.getPackageName(), PackageManager.GET_META_DATA); if (applicationInfo != null) { if (applicationInfo.metaData != null) { resultData = applicationInfo.metaData.getString(key); } } } } catch (PackageManager.NameNotFoundException e) { LogUtil.e(TAG, "", e); } return resultData; }
From source file:com.google.android.gms.common.GooglePlayServicesUtilLight.java
public static String zzap(Context context) { Object obj = context.getApplicationInfo().name; if (!TextUtils.isEmpty(obj)) { return obj; }//from w ww . ja va2 s. co m ApplicationInfo applicationInfo; String packageName = context.getPackageName(); PackageManager packageManager = context.getApplicationContext().getPackageManager(); try { applicationInfo = packageManager.getApplicationInfo(context.getPackageName(), 0); } catch (NameNotFoundException e) { applicationInfo = null; } return applicationInfo != null ? packageManager.getApplicationLabel(applicationInfo).toString() : packageName; }
From source file:fr.simon.marquis.preferencesmanager.util.Utils.java
/** * Put User id and Group id back to the corresponding app with this cmd: `chown uid.gid filename` * * @param ctx Context/*from w w w. j a v a 2 s.c o m*/ * @param file The file to fix * @param packageName The packageName of the app * @return true if success */ private static boolean fixUserAndGroupId(Context ctx, String file, String packageName) { Log.d(TAG, String.format("fixUserAndGroupId(%s, %s)", file, packageName)); String uid; PackageManager pm = ctx.getPackageManager(); if (pm == null) { return false; } try { ApplicationInfo appInfo = pm.getApplicationInfo(packageName, 0); uid = String.valueOf(appInfo.uid); } catch (PackageManager.NameNotFoundException e) { Log.e(TAG, "error while getting uid", e); return false; } if (TextUtils.isEmpty(uid)) { Log.d(TAG, "uid is undefined"); return false; } CommandCapture cmd = new CommandCapture(CMD_CHOWN.hashCode(), false, String.format(CMD_CHOWN, uid, uid, file)); synchronized (cmd) { try { RootTools.getShell(true).add(cmd).wait(); } catch (Exception e) { Log.e(TAG, "Error in fixPermissions", e); return false; } } return true; }
From source file:com.wbtech.common.CommonUtil.java
/** * ?APPKEY// www . j a va 2 s . c om * * @param context * @return appkey */ public static String getAppKey(Context paramContext) { String umsAppkey; try { PackageManager localPackageManager = paramContext.getPackageManager(); ApplicationInfo localApplicationInfo = localPackageManager .getApplicationInfo(paramContext.getPackageName(), 128); if (localApplicationInfo != null) { String str = localApplicationInfo.metaData.getString("UMS_APPKEY"); if (str != null) { umsAppkey = str; return umsAppkey.toString(); } if (UmsConstants.DebugMode) Log.e("UmsAgent", "Could not read UMS_APPKEY meta-data from AndroidManifest.xml."); } } catch (Exception localException) { if (UmsConstants.DebugMode) { Log.e("UmsAgent", "Could not read UMENG_APPKEY meta-data from AndroidManifest.xml."); localException.printStackTrace(); } } return null; }
From source file:Main.java
public static void send(Context context, String path) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND); PackageManager pm = context.getPackageManager(); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setType("*/*"); intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(path))); List<ResolveInfo> list = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); boolean flag = false; for (ResolveInfo info : list) { if (info.activityInfo.packageName.toLowerCase().contains("bluetooth") || info.activityInfo.name.toLowerCase().contains("bluetooth")) { ApplicationInfo appInfo = null; try { appInfo = pm.getApplicationInfo(info.activityInfo.packageName, PackageManager.GET_META_DATA); } catch (PackageManager.NameNotFoundException e) { }//w ww . j ava 2 s .c o m if (appInfo != null && (appInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 0 && (appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { intent.setClassName(info.activityInfo.packageName, info.activityInfo.name); flag = true; break; } } } if (!flag) { return; } context.startActivity(intent); }
From source file:com.google.android.gms.common.GooglePlayServicesUtil.java
private static String m119u(Context context) { Object obj = context.getApplicationInfo().name; if (!TextUtils.isEmpty(obj)) { return obj; }/*from ww w .j a va2s.c om*/ ApplicationInfo applicationInfo; String packageName = context.getPackageName(); PackageManager packageManager = context.getApplicationContext().getPackageManager(); try { applicationInfo = packageManager.getApplicationInfo(context.getPackageName(), 0); } catch (NameNotFoundException e) { applicationInfo = null; } return applicationInfo != null ? packageManager.getApplicationLabel(applicationInfo).toString() : packageName; }
From source file:de.madvertise.android.sdk.MadvertiseUtil.java
/** * Returns the madvertise token//from w w w . j a v a 2 s.com * * @param context * application context * @return madvertise_token from AndroidManifest.xml or null */ public static String getToken(final Context context, MadvertiseViewCallbackListener listener) { String madvertiseToken = null; PackageManager packageManager = context.getPackageManager(); try { ApplicationInfo applicationInfo = packageManager.getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA); madvertiseToken = applicationInfo.metaData.getString(MADVERTISE_SITE_TOKEN); } catch (Exception e) { e.printStackTrace(); } if (madvertiseToken == null) { MadvertiseUtil.logMessage(null, Log.DEBUG, "Could not fetch \"madvertise_site_token\" from AndroidManifest.xml"); if (listener != null) { listener.onError(new IllegalArgumentException( "Could not fetch \"madvertise_site_token\" from AndroidManifest.xml")); } } return madvertiseToken; }
From source file:org.deviceconnect.android.manager.core.util.DConnectUtil.java
/** * ??????./* www. j a va 2 s. c om*/ * * @param context * @param packageName ??? * @param iconId ?ID * @return ?? */ public static Drawable loadPluginIcon(final Context context, final String packageName, final Integer iconId) { PackageManager pkgMgr = context.getPackageManager(); Drawable icon; if (iconId != null) { icon = ResourcesCompat.getDrawable(context.getResources(), iconId, null); } else { try { ApplicationInfo info = pkgMgr.getApplicationInfo(packageName, 0); icon = pkgMgr.getApplicationIcon(info.packageName); } catch (PackageManager.NameNotFoundException e) { icon = null; if (BuildConfig.DEBUG) { Log.d("Manager", "Icon is not found."); } } } return icon; }
From source file:tr.com.turkcellteknoloji.turkcellupdater.Utilities.java
static boolean isPackageInstalled(Context context, String packageName) { checkArgumentNotNull("context", context); final PackageManager packageManager = context.getPackageManager(); if (packageManager == null) { throw new IllegalStateException("packageManager is null."); }/*from w ww .j ava2 s .c o m*/ ApplicationInfo ai = null; try { ai = packageManager.getApplicationInfo(packageName, 0); } catch (NameNotFoundException e) { return false; } return ai != null; }