List of usage examples for android.content.pm PackageManager getApplicationInfo
public abstract ApplicationInfo getApplicationInfo(String packageName, @ApplicationInfoFlags int flags) throws NameNotFoundException;
From source file:io.lqd.sdk.gcm.LQMessageHandler.java
private static int getAppIconInt(Context context) { PackageManager manager = context.getPackageManager(); try {//from w ww .j a v a 2s . co m ApplicationInfo appinfo = manager.getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA); Bundle b = appinfo.metaData; if (b != null && b.getInt("io.lqd.sdk.notification_icon", 0) > 0) return b.getInt("io.lqd.sdk.notification_icon"); return appinfo.icon; } catch (PackageManager.NameNotFoundException e) { return android.R.drawable.sym_def_app_icon; } }
From source file:Main.java
/** * whether packageName is system application *//*from w w w . ja va 2s . c o m*/ public static boolean isSystemApplication(Context context, String packageName) { PackageManager packageManager = context.getPackageManager(); if (packageManager == null || packageName == null || packageName.length() == 0) { return false; } try { ApplicationInfo app = packageManager.getApplicationInfo(packageName, 0); return (app != null && (app.flags & ApplicationInfo.FLAG_SYSTEM) > 0); } catch (Exception e) { e.printStackTrace(); } return false; }
From source file:io.lqd.sdk.LQPushHandler.java
private static String getAppName(Context context) { PackageManager manager = context.getPackageManager(); try {//from w w w .j a v a2 s .c om ApplicationInfo appinfo = manager.getApplicationInfo(context.getPackageName(), 0); return manager.getApplicationLabel(appinfo).toString(); } catch (NameNotFoundException e) { return ""; } }
From source file:io.lqd.sdk.LQPushHandler.java
private static int getAppIconInt(Context context) { PackageManager manager = context.getPackageManager(); try {/*from w w w . j a v a 2s .co m*/ ApplicationInfo appinfo = manager.getApplicationInfo(context.getPackageName(), 0); return appinfo.icon; } catch (NameNotFoundException e) { return android.R.drawable.sym_def_app_icon; } }
From source file:com.dm.material.dashboard.candybar.helpers.DrawableHelper.java
@Nullable public static Bitmap getHighQualityIcon(@NonNull Context context, String packageName) { try {/*w w w . j a v a 2s .c o m*/ PackageManager packageManager = context.getPackageManager(); ApplicationInfo info = packageManager.getApplicationInfo(packageName, PackageManager.GET_META_DATA); Resources resources = packageManager.getResourcesForApplication(packageName); int density = DisplayMetrics.DENSITY_XXHIGH; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { density = DisplayMetrics.DENSITY_XXXHIGH; } Drawable drawable = ResourcesCompat.getDrawableForDensity(resources, info.icon, density, null); if (drawable != null) return ((BitmapDrawable) drawable).getBitmap(); } catch (Exception | OutOfMemoryError e) { LogUtil.e(Log.getStackTraceString(e)); } return null; }
From source file:Main.java
/** * whether packageName is system application * * @param packageManager//w w w.jav a2 s .c o m * @param packageName * @return <ul> * <li>if packageManager is null, return false</li> * <li>if package name is null or is empty, return false</li> * <li>if package name not exit, return false</li> * <li>if package name exit, but not system app, return false</li> * <li>else return true</li> * </ul> */ public static boolean isSystemApplication(PackageManager packageManager, String packageName) { if (packageManager == null || packageName == null || packageName.length() == 0) { return false; } try { ApplicationInfo app = packageManager.getApplicationInfo(packageName, 0); return (app != null && (app.flags & ApplicationInfo.FLAG_SYSTEM) > 0); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return false; }
From source file:Main.java
/** * whether packageName is system application * //from w ww . j a va 2 s.c o m * @param packageManager * @param packageName * @return <ul> * <li>if packageManager is null, return false</li> * <li>if package name is null or is empty, return false</li> * <li>if package name not exit, return false</li> * <li>if package name exit, but not system app, return false</li> * <li>else return true</li> * </ul> */ public static boolean isSystemApplication(PackageManager packageManager, String packageName) { if (packageManager == null || packageName == null || packageName.length() == 0) { return false; } try { ApplicationInfo app = packageManager.getApplicationInfo(packageName, 0); return (app != null && (app.flags & ApplicationInfo.FLAG_SYSTEM) > 0); } catch (NameNotFoundException e) { e.printStackTrace(); } return false; }
From source file:Main.java
private static int b(Context paramContext, int paramInt) { PackageManager localPackageManager = paramContext.getPackageManager(); int i;/*from w w w . j a v a 2 s.co m*/ try { PackageInfo localPackageInfo = localPackageManager.getPackageInfo("com.google.android.apps.plus", 0); ApplicationInfo localApplicationInfo = localPackageManager .getApplicationInfo("com.google.android.apps.plus", 0); if (localPackageInfo.versionCode < paramInt) return 2; boolean bool = localApplicationInfo.enabled; i = 0; if (!bool) return 3; } catch (PackageManager.NameNotFoundException localNameNotFoundException) { i = 1; } return i; }
From source file:Main.java
private static ApplicationInfo getApplicationInfoFromPackageManager(final int flags) { assert null != mContext; if (null == mContext) { return null; }//ww w. jav a 2 s.c o m final PackageManager pm = mContext.getPackageManager(); if (null == pm) { return null; } ApplicationInfo appInfo = null; try { appInfo = pm.getApplicationInfo(mContext.getPackageName(), flags); } catch (PackageManager.NameNotFoundException e) { } return appInfo; }
From source file:Main.java
public static String getAppName(Context c, int uid, boolean withUid) { if (sSystemUids.containsKey(uid)) { return sSystemUids.get(uid); }/*w w w . ja v a 2 s . c om*/ PackageManager pm = c.getPackageManager(); String appName = "Unknown"; String[] packages = pm.getPackagesForUid(uid); if (packages != null) { try { if (packages.length == 1) { appName = pm.getApplicationLabel(pm.getApplicationInfo(packages[0], 0)).toString(); } else if (packages.length > 1) { appName = ""; for (int i = 0; i < packages.length; i++) { appName += packages[i]; if (i < packages.length - 1) { appName += ", "; } } } } catch (NameNotFoundException e) { Log.e(TAG, "Package name not found", e); } } else { Log.e(TAG, "Package not found for uid " + uid); } if (withUid) { appName += " (" + uid + ")"; } return appName; }