List of usage examples for android.content Context getPackageManager
public abstract PackageManager getPackageManager();
From source file:Main.java
public static String getVersionName(Context context) { try {// www .j a v a2 s. com PackageManager packageManager = context.getPackageManager(); return packageManager.getPackageInfo(context.getPackageName(), 0).versionName; } catch (Throwable error) { error.printStackTrace(); return ""; } }
From source file:Main.java
public static boolean isDebuggable(Context context) { PackageManager pacMan = context.getPackageManager(); String pacName = context.getPackageName(); ApplicationInfo appInfo = null;//from w w w. ja va2 s. c o m try { appInfo = pacMan.getApplicationInfo(pacName, 0); } catch (NameNotFoundException e) { e.printStackTrace(); } if (appInfo != null) { if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) { return true; } else { return false; } } else { return false; } }
From source file:Main.java
public static boolean isWeiboInstalled(Context context) { final PackageManager packageManager = context.getPackageManager(); List<PackageInfo> infos = packageManager.getInstalledPackages(0); if (infos != null) { for (PackageInfo info : infos) { if (TextUtils.equals(info.packageName, "com.sina.weibo")) { return true; }/*from w ww. j a va 2 s . c o m*/ } } return false; }
From source file:Main.java
public static boolean isQqInstalled(Context context) { final PackageManager packageManager = context.getPackageManager(); List<PackageInfo> infos = packageManager.getInstalledPackages(0); if (infos != null) { for (PackageInfo info : infos) { if (TextUtils.equals(info.packageName, "com.tencent.mobileqq")) { return true; }//from ww w.j a v a2s. c om } } return false; }
From source file:Main.java
public static boolean isWechatInstalled(Context context) { final PackageManager packageManager = context.getPackageManager(); List<PackageInfo> infos = packageManager.getInstalledPackages(0); if (infos != null) { for (PackageInfo info : infos) { if (TextUtils.equals(info.packageName, "com.tencent.mm")) { return true; }// w ww .j a v a 2s. co m } } return false; }
From source file:Main.java
/** * Check if a certain application is installed on a device. * * @param context the applications context. * @param packageName the package name that you want to check. * * @return true if the application is installed, false otherwise. *//*from ww w. j a v a2 s.c o m*/ public static boolean isApplicationInstalled(Context context, String packageName) { PackageManager pm = context.getPackageManager(); try { // Check if the package name exists, if exception is thrown, package name does not exist. pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES); return true; } catch (PackageManager.NameNotFoundException e) { return false; } }
From source file:Main.java
public static int getVersionCode(Context context) { try {//from w w w . j av a 2 s . c o m PackageManager packageManager = context.getPackageManager(); PackageInfo packInfo = packageManager.getPackageInfo(context.getPackageName(), 0); return packInfo.versionCode; } catch (Exception e) { e.printStackTrace(); } return 13; }
From source file:Main.java
private static boolean isAppInstalled(Context context, String uri) { try {/* w w w. j a va 2 s .com*/ PackageManager pm = context.getPackageManager(); pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES); return true; } catch (PackageManager.NameNotFoundException e) { return false; } }
From source file:Main.java
public static String getAppInfoName(Context context) { try {/*from w w w .j a va 2 s . c om*/ PackageManager pm = context.getPackageManager(); PackageInfo packageinfo = pm.getPackageInfo(context.getPackageName(), 0); String versionname = packageinfo.versionName; return versionname; } catch (NameNotFoundException e) { e.printStackTrace(); } return ""; }
From source file:Main.java
/** * get UnInstallApkPackageName// w w w.j a va 2 s .co m * * @param context Context * @param apkPath apkPath * @return apk PackageName */ public static String getUnInstallApkPackageName(Context context, String apkPath) { PackageManager pm = context.getPackageManager(); PackageInfo info = pm.getPackageArchiveInfo(apkPath, PackageManager.GET_ACTIVITIES); if (info != null) { ApplicationInfo appInfo = info.applicationInfo; if (appInfo != null) { return appInfo.packageName; } } return null; }