List of usage examples for android.content Context getPackageManager
public abstract PackageManager getPackageManager();
From source file:Main.java
public static boolean hasIntentActivities(Context context, Intent intent) { PackageManager packageManager = context.getPackageManager(); List<ResolveInfo> list = packageManager.queryIntentActivities(intent, 0); return list.size() > 0; }
From source file:Main.java
public static int getVersionCode(Context context) { try {//from ww w .jav a 2s.c o m PackageManager manager = context.getPackageManager(); PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0); return info.versionCode; } catch (Exception e) { e.printStackTrace(); return 0; } }
From source file:Main.java
public static boolean isInstalled(Context context, String packageName) { PackageManager pm = context.getPackageManager(); boolean installed = false; try {// w w w.j ava 2s . co m pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES); installed = true; } catch (Exception e) { e.printStackTrace(); } return installed; }
From source file:Main.java
/** * Extract the app full file system location. * @param context of the application that will be use as base point. * @return Full application file system url. * @throws PackageManager.NameNotFoundException *///from w ww.ja v a 2 s . co m private static String getSourcePath(Context context) throws PackageManager.NameNotFoundException { return context.getPackageManager().getApplicationInfo(context.getPackageName(), 0).sourceDir; }
From source file:Main.java
public static boolean isIntentAvailable(Context context, Intent intent) { PackageManager packageManager = context.getPackageManager(); List<ResolveInfo> resolves = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); boolean isIntentAvailable = resolves.size() > 0; return isIntentAvailable; }
From source file:Main.java
@TargetApi(Build.VERSION_CODES.M) public static List<String> getCustomTabSupportingPackages(Context context) { PackageManager pm = context.getPackageManager(); Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com")); // Get all apps that can handle VIEW intents. List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(activityIntent, PackageManager.MATCH_ALL); List<String> packagesSupportingCustomTabs = new ArrayList<>(); for (ResolveInfo info : resolvedActivityList) { Intent serviceIntent = new Intent(); serviceIntent.setAction(ACTION_CUSTOM_TABS_CONNECTION); serviceIntent.setPackage(info.activityInfo.packageName); if (pm.resolveService(serviceIntent, 0) != null) { packagesSupportingCustomTabs.add(info.activityInfo.packageName); }//from w w w . j av a 2 s . c om } return packagesSupportingCustomTabs; }
From source file:Main.java
public static int getAppVersionCode(Context context) { try {/*from www . j a v a2 s .c om*/ PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); if (packageInfo != null) { return packageInfo.versionCode; } } catch (Exception e) { } return 1; }
From source file:Main.java
/** * Check if package installed/* w w w . j a va 2 s.c o m*/ * * @param context Context of current app * @param uri Package of application to check * @return true if passed package installed */ public static boolean isAppInstalled(Context context, String uri) { PackageManager pm = context.getPackageManager(); boolean appInstalled; try { assert pm != null; pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES); appInstalled = true; } catch (PackageManager.NameNotFoundException e) { appInstalled = false; } return appInstalled; }
From source file:Main.java
public static String getVersion(Context context) { try {//from www .j a v a2s .c om PackageManager manager = context.getPackageManager(); PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0); return info.versionName; } catch (Exception e) { e.printStackTrace(); } return ""; }
From source file:Main.java
public static String getVersion(Context context) { try {//from w ww . j ava 2 s . c om PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return packageInfo.versionName; } catch (Exception e) { e.printStackTrace(); } return ""; }