List of usage examples for android.content.pm PackageManager getPackageInfo
public abstract PackageInfo getPackageInfo(VersionedPackage versionedPackage, @PackageInfoFlags int flags) throws NameNotFoundException;
From source file:dk.microting.softkeyboard.autoupdateapk.AutoUpdateApk.java
private static boolean haveInternetPermissions() { Set<String> required_perms = new HashSet<String>(); required_perms.add("android.permission.INTERNET"); required_perms.add("android.permission.ACCESS_WIFI_STATE"); required_perms.add("android.permission.ACCESS_NETWORK_STATE"); PackageManager pm = context.getPackageManager(); String packageName = context.getPackageName(); int flags = PackageManager.GET_PERMISSIONS; PackageInfo packageInfo = null;/*from w ww . j a v a2 s . c o m*/ try { packageInfo = pm.getPackageInfo(packageName, flags); versionCode = packageInfo.versionCode; } catch (NameNotFoundException e) { e.printStackTrace(); } if (packageInfo.requestedPermissions != null) { for (String p : packageInfo.requestedPermissions) { //Log.v(TAG, "permission: " + p.toString()); required_perms.remove(p); } if (required_perms.size() == 0) { return true; // permissions are in order } // something is missing for (String p : required_perms) { Log.e(TAG, "required permission missing: " + p); } } Log.e(TAG, "INTERNET/WIFI access required, but no permissions are found in Manifest.xml"); return false; }
From source file:com.wbtech.common.CommonUtil.java
/** * ???// w w w . ja v a 2s . c o m * @param context * @return */ public static String getVersion(Context context) { String versionName = ""; try { PackageManager pm = context.getPackageManager(); PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0); versionName = pi.versionName; if (versionName == null || versionName.length() <= 0) { return ""; } } catch (Exception e) { if (UmsConstants.DebugMode) { Log.e("UmsAgent", "Exception", e); } } return versionName; }
From source file:com.entertailion.android.slideshow.utils.Utils.java
/** * Log device info./*from w w w . ja v a 2 s . c o m*/ * * @param context */ public static final void logDeviceInfo(Context context) { try { PackageManager pm = context.getPackageManager(); PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0); Log.i(LOG_TAG, "Version=" + pi.versionName); Log.i(LOG_TAG, "IP Address=" + Utils.getLocalIpAddress()); Log.i(LOG_TAG, "android.os.Build.VERSION.RELEASE=" + android.os.Build.VERSION.RELEASE); Log.i(LOG_TAG, "android.os.Build.VERSION.INCREMENTAL=" + android.os.Build.VERSION.INCREMENTAL); Log.i(LOG_TAG, "android.os.Build.DEVICE=" + android.os.Build.DEVICE); Log.i(LOG_TAG, "android.os.Build.MODEL=" + android.os.Build.MODEL); Log.i(LOG_TAG, "android.os.Build.PRODUCT=" + android.os.Build.PRODUCT); Log.i(LOG_TAG, "android.os.Build.MANUFACTURER=" + android.os.Build.MANUFACTURER); Log.i(LOG_TAG, "android.os.Build.BRAND=" + android.os.Build.BRAND); } catch (NameNotFoundException e) { Log.e(LOG_TAG, "logDeviceInfo", e); } }
From source file:com.wbtech.common.CommonUtil.java
/** * ????/*from w w w .ja va 2 s .c om*/ * @param paramContext * @return */ public static String getCurVersion(Context paramContext) { String curversion = ""; try { // ---get the package info--- PackageManager pm = paramContext.getPackageManager(); PackageInfo pi = pm.getPackageInfo(paramContext.getPackageName(), 0); curversion = pi.versionName; if (curversion == null || curversion.length() <= 0) { return ""; } } catch (Exception e) { if (UmsConstants.DebugMode) { Log.e("VersionInfo", "Exception", e); } } return curversion; }
From source file:com.battlelancer.seriesguide.util.Utils.java
/** * Returns if the user has a valid copy of X Pass installed. *//* w ww. j a v a2 s .c o m*/ private static boolean hasUnlockKeyInstalled(Context context) { try { // Get our signing key PackageManager manager = context.getPackageManager(); PackageInfo appInfoSeriesGuide = manager.getPackageInfo( context.getApplicationContext().getPackageName(), PackageManager.GET_SIGNATURES); // Try to find the X signing key PackageInfo appInfoSeriesGuideX = manager.getPackageInfo("com.battlelancer.seriesguide.x", PackageManager.GET_SIGNATURES); final String ourKey = appInfoSeriesGuide.signatures[0].toCharsString(); final String xKey = appInfoSeriesGuideX.signatures[0].toCharsString(); return ourKey.equals(xKey); } catch (NameNotFoundException e) { // Expected exception that occurs if the package is not present. } return false; }
From source file:fr.inria.ucn.Helpers.java
/** * Collectors and Listeners should use this method to send the results to the service. * @param c// ww w . ja v a 2s. c om * @param cid data collection id (maps to mongodb collection used to store the data) * @param ts periodic collection timestamp or event time if triggered by timestamp * @param data */ @SuppressLint("SimpleDateFormat") public static void sendResultObj(Context c, String cid, long ts, JSONObject data) { try { // wrap the collected data object to a common object format JSONObject res = new JSONObject(); // data collection in the backend db res.put("collection", cid); // store unique user id to each result object res.put("uid", getDeviceUuid(c)); // app version to help to detect data format changes try { PackageManager manager = c.getPackageManager(); PackageInfo info = manager.getPackageInfo(c.getPackageName(), 0); res.put("app_version_name", info.versionName); res.put("app_version_code", info.versionCode); } catch (NameNotFoundException e) { } // event and current time in UTC JSON date format SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S'Z'"); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); res.put("ts_event", sdf.format(new Date(ts))); res.put("ts", sdf.format(new Date())); res.put("tz", TimeZone.getDefault().getID()); // devices current timezone res.put("tz_offset", TimeZone.getDefault().getOffset(ts)); // ts offset to this event // the data obj res.put("data", data); // ask the service to handle the data Intent intent = new Intent(c, CollectorService.class); intent.setAction(Constants.ACTION_DATA); intent.putExtra(Constants.INTENT_EXTRA_DATA, res.toString()); c.startService(intent); Log.d(Constants.LOGTAG, res.toString(4)); } catch (JSONException ex) { Log.w(Constants.LOGTAG, "failed to create json obj", ex); } }
From source file:com.google.android.gms.common.GooglePlayServicesUtil.java
public static boolean m111b(PackageManager packageManager, String str) { try {/* w ww .j ava 2 s.c o m*/ return m105a(packageManager, packageManager.getPackageInfo(str, 64)); } catch (NameNotFoundException e) { if (Log.isLoggable("GooglePlayServicesUtil", 3)) { Log.d("GooglePlayServicesUtil", "Package manager can't find package " + str + ", defaulting to false"); } return false; } }
From source file:com.gsbabil.antitaintdroid.UtilityFunctions.java
public static String currentDirectory() { PackageManager pkgManager = MyApp.context.getPackageManager(); String pkgName = MyApp.context.getPackageName(); PackageInfo pkg = new PackageInfo(); try {// w w w. j a va 2 s.co m pkg = pkgManager.getPackageInfo(pkgName, 0); } catch (Throwable e) { Log.i(MyApp.TAG, e.getMessage().toString()); } return pkg.applicationInfo.dataDir; }
From source file:com.oliversride.wordryo.UpdateCheckReceiver.java
public static void checkVersions(Context context, boolean fromUI) { JSONObject params = new JSONObject(); PackageManager pm = context.getPackageManager(); String packageName = context.getPackageName(); String installer = pm.getInstallerPackageName(packageName); if ("com.google.android.feedback".equals(installer) || "com.android.vending".equals(installer)) { // Do nothing; it's a Market app } else {/*from ww w. j a va 2s. com*/ try { int versionCode = pm.getPackageInfo(packageName, 0).versionCode; JSONObject appParams = new JSONObject(); appParams.put(k_NAME, packageName); appParams.put(k_AVERS, versionCode); appParams.put(k_GVERS, GitVersion.VERS); appParams.put(k_INSTALLER, installer); if (devOK(context)) { appParams.put(k_DEVOK, true); } params.put(k_APP, appParams); params.put(k_DEVID, XWPrefs.getDevID(context)); } catch (PackageManager.NameNotFoundException nnfe) { DbgUtils.loge(nnfe); } catch (org.json.JSONException jse) { DbgUtils.loge(jse); } } JSONArray dictParams = new JSONArray(); DictUtils.DictAndLoc[] dals = DictUtils.dictList(context); for (int ii = 0; ii < dals.length; ++ii) { DictUtils.DictAndLoc dal = dals[ii]; switch (dal.loc) { // case DOWNLOAD: case EXTERNAL: case INTERNAL: dictParams.put(makeDictParams(context, dal, ii)); } } if (0 < dictParams.length()) { try { params.put(k_DICTS, dictParams); params.put(k_DEVID, XWPrefs.getDevID(context)); } catch (org.json.JSONException jse) { DbgUtils.loge(jse); } } if (0 < params.length()) { new UpdateQueryTask(context, params, fromUI, pm, packageName, dals).execute(); } }
From source file:it.mb.whatshare.Utils.java
/** * Checks whether the app that's running has the * <code>android:debuggable</code> flag set, and enables/disables all log * calls accordingly./*from ww w .ja v a2 s . c o m*/ * * @param context * the caller activity */ public static void checkDebug(Context context) { if (!debuggableFlagChecked) { debuggableFlagChecked = true; PackageManager manager = context.getPackageManager(); try { PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0); debugEnabled = (info.applicationInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0; } catch (NameNotFoundException e) { e.printStackTrace(); // let's keep debug disabled } } // else it's already been checked once, don't check anymore }