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.savor.ads.core.Session.java
private void getApplicationInfo() { final PackageManager pm = mContext.getPackageManager(); try {//w w w.j a va2 s . c o m final PackageInfo pi = pm.getPackageInfo(mContext.getPackageName(), 0); versionName = pi.versionName; versionCode = pi.versionCode; final ApplicationInfo ai = pm.getApplicationInfo(mContext.getPackageName(), PackageManager.GET_META_DATA); debugType = "1";// ai.metaData.get("app_debug").toString(); if ("1".equals(debugType)) { // developer mode isDebug = true; } else if ("0".equals(debugType)) { // release mode isDebug = false; } LogUtils.allow = isDebug; appName = String.valueOf(ai.loadLabel(pm)); LogUtils.appTagPrefix = appName; } catch (NameNotFoundException e) { LogUtils.d("met some error when get application info"); } }
From source file:com.google.android.gms.common.zze.java
@Deprecated public static int isGooglePlayServicesAvailable(Context context) { if (zzd.zzakE) { return GOOGLE_PLAY_SERVICES_VERSION_CODE; }/*from w ww . j a v a2s . com*/ PackageManager packageManager = context.getPackageManager(); try { context.getResources().getString(C0434R.string.common_google_play_services_unknown_issue); } catch (Throwable th) { Log.e("GooglePlayServicesUtil", "The Google Play services resources were not found. Check your project configuration to ensure that the resources are included."); } if (!GOOGLE_PLAY_SERVICES_PACKAGE.equals(context.getPackageName())) { zzan(context); } try { PackageInfo packageInfo = packageManager.getPackageInfo(GOOGLE_PLAY_SERVICES_PACKAGE, 64); zzf zzoO = zzf.zzoO(); if (!zzmu.zzaw(context)) { try { if (zzoO.zza(packageManager.getPackageInfo(GOOGLE_PLAY_STORE_PACKAGE, 8256), zzd.zzafK) == null) { Log.w("GooglePlayServicesUtil", "Google Play Store signature invalid."); return 9; } if (zzoO.zza(packageInfo, zzoO.zza( packageManager.getPackageInfo(GOOGLE_PLAY_STORE_PACKAGE, 8256), zzd.zzafK)) == null) { Log.w("GooglePlayServicesUtil", "Google Play services signature invalid."); return 9; } } catch (NameNotFoundException e) { Log.w("GooglePlayServicesUtil", "Google Play Store is neither installed nor updating."); return 9; } } else if (zzoO.zza(packageInfo, zzd.zzafK) == null) { Log.w("GooglePlayServicesUtil", "Google Play services signature invalid."); return 9; } if (zzmx.zzco(packageInfo.versionCode) < zzmx.zzco(GOOGLE_PLAY_SERVICES_VERSION_CODE)) { Log.w("GooglePlayServicesUtil", "Google Play services out of date. Requires " + GOOGLE_PLAY_SERVICES_VERSION_CODE + " but found " + packageInfo.versionCode); return 2; } ApplicationInfo applicationInfo = packageInfo.applicationInfo; if (applicationInfo == null) { try { applicationInfo = packageManager.getApplicationInfo(GOOGLE_PLAY_SERVICES_PACKAGE, GOOGLE_PLAY_SERVICES_VERSION_CODE); } catch (Throwable e2) { Log.wtf("GooglePlayServicesUtil", "Google Play services missing when getting application info.", e2); return 1; } } return !applicationInfo.enabled ? 3 : GOOGLE_PLAY_SERVICES_VERSION_CODE; } catch (NameNotFoundException e3) { Log.w("GooglePlayServicesUtil", "Google Play services is missing."); return 1; } }
From source file:com.google.android.gms.common.GooglePlayServicesUtilLight.java
@Deprecated public static int isGooglePlayServicesAvailable(Context context) { if (zzd.zzavq) { return 0; }/* w w w .j a v a2 s . c o m*/ PackageManager packageManager = context.getPackageManager(); try { context.getResources().getString(C0158R.string.common_google_play_services_unknown_issue); } catch (Throwable th) { Log.e("GooglePlayServicesUtil", "The Google Play services resources were not found. Check your project configuration to ensure that the resources are included."); } if (!"com.google.android.gms".equals(context.getPackageName())) { zzao(context); } try { PackageInfo packageInfo = packageManager.getPackageInfo("com.google.android.gms", 64); GoogleSignatureVerifier instance = GoogleSignatureVerifier.getInstance(); if (!zzh.zzax(context)) { try { if (instance.zza(packageManager.getPackageInfo("com.android.vending", 8256), zzcm.zzapU) == null) { Log.w("GooglePlayServicesUtil", "Google Play Store signature invalid."); return 9; } if (instance.zza(packageInfo, instance .zza(packageManager.getPackageInfo("com.android.vending", 8256), zzcm.zzapU)) == null) { Log.w("GooglePlayServicesUtil", "Google Play services signature invalid."); return 9; } } catch (NameNotFoundException e) { Log.w("GooglePlayServicesUtil", "Google Play Store is neither installed nor updating."); return 9; } } else if (instance.zza(packageInfo, zzcm.zzapU) == null) { Log.w("GooglePlayServicesUtil", "Google Play services signature invalid."); return 9; } if (zzk.zzdD(packageInfo.versionCode) < zzk.zzdD(GOOGLE_PLAY_SERVICES_VERSION_CODE)) { Log.w("GooglePlayServicesUtil", "Google Play services out of date. Requires " + GOOGLE_PLAY_SERVICES_VERSION_CODE + " but found " + packageInfo.versionCode); return 2; } ApplicationInfo applicationInfo = packageInfo.applicationInfo; if (applicationInfo == null) { try { applicationInfo = packageManager.getApplicationInfo("com.google.android.gms", 0); } catch (Throwable e2) { Log.wtf("GooglePlayServicesUtil", "Google Play services missing when getting application info.", e2); return 1; } } return !applicationInfo.enabled ? 3 : 0; } catch (NameNotFoundException e3) { Log.w("GooglePlayServicesUtil", "Google Play services is missing."); return 1; } }
From source file:me.piebridge.bible.Bible.java
private void checkApkData() { Log.d(TAG, "checking apkdata"); try {/* w w w. ja va 2 s . c o m*/ String packageName = mContext.getPackageName(); PackageManager pm = mContext.getPackageManager(); SharedPreferences preference = PreferenceManager.getDefaultSharedPreferences(mContext); ApplicationInfo ai = pm.getApplicationInfo(packageName, 0); for (String applicationName : pm.getPackagesForUid(ai.uid)) { if (packageName.equals(applicationName)) { continue; } // version String version = applicationName.replace(packageName + ".", ""); // resources Resources resources = mContext .createPackageContext(applicationName, Context.CONTEXT_IGNORE_SECURITY).getResources(); // newVersion int versionCode = pm.getPackageInfo(applicationName, 0).versionCode; boolean newVersion = (preference.getInt(version, 0) != versionCode); // resid int resid = resources.getIdentifier("a", "raw", applicationName); if (resid == 0) { resid = resources.getIdentifier("xa", "raw", applicationName); } if (resid == 0) { Log.d(TAG, "package " + applicationName + " has no R.raw.a nor R.raw.xa"); continue; } // file File file; if (versionpaths.containsKey(version)) { file = new File(versionpaths.get(version)); } else { file = new File(getExternalFilesDirWrapper(), version + ".sqlite3"); } if (file.exists() && !file.isFile()) { file.delete(); } boolean unpack = unpackRaw(resources, newVersion, resid, file); if (newVersion && unpack) { preference.edit().putInt(version, versionCode).commit(); } } } catch (Exception e) { Log.e(TAG, "", e); } }
From source file:plugin.google.maps.GoogleMaps.java
@SuppressLint("NewApi") @Override// w w w . j av a2 s .c om public void initialize(final CordovaInterface cordova, final CordovaWebView webView) { super.initialize(cordova, webView); activity = cordova.getActivity(); density = Resources.getSystem().getDisplayMetrics().density; root = (ViewGroup) webView.getParent(); // Is this app in debug mode? try { PackageManager manager = activity.getPackageManager(); ApplicationInfo appInfo = manager.getApplicationInfo(activity.getPackageName(), 0); isDebug = (appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) == ApplicationInfo.FLAG_DEBUGGABLE; } catch (Exception e) { } Log.i("CordovaLog", "This app uses phonegap-googlemaps-plugin version " + PLUGIN_VERSION); if (isDebug) { cordova.getThreadPool().execute(new Runnable() { @Override public void run() { try { JSONArray params = new JSONArray(); params.put("get"); params.put("http://plugins.cordova.io/api/plugin.google.maps"); HttpRequest httpReq = new HttpRequest(); httpReq.initialize(cordova, null); httpReq.execute("execute", params, new CallbackContext("version_check", webView) { @Override public void sendPluginResult(PluginResult pluginResult) { if (pluginResult.getStatus() == PluginResult.Status.OK.ordinal()) { try { JSONObject result = new JSONObject(pluginResult.getStrMessage()); JSONObject distTags = result.getJSONObject("dist-tags"); String latestVersion = distTags.getString("latest"); if (latestVersion.equals(PLUGIN_VERSION) == false) { Log.i("CordovaLog", "phonegap-googlemaps-plugin version " + latestVersion + " is available."); } } catch (JSONException e) { } } } }); } catch (Exception e) { } } }); } cordova.getActivity().runOnUiThread(new Runnable() { @SuppressLint("NewApi") public void run() { /* try { Method method = webView.getClass().getMethod("getSettings"); WebSettings settings = (WebSettings)method.invoke(null); settings.setRenderPriority(RenderPriority.HIGH); settings.setCacheMode(WebSettings.LOAD_NO_CACHE); } catch (Exception e) { e.printStackTrace(); } */ if (Build.VERSION.SDK_INT >= 11) { webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); } root.setBackgroundColor(Color.WHITE); if (VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) { activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN); } if (VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) { Log.d(TAG, "Google Maps Plugin reloads the browser to change the background color as transparent."); webView.setBackgroundColor(0); try { Method method = webView.getClass().getMethod("reload"); method.invoke(webView); } catch (Exception e) { e.printStackTrace(); } } } }); }
From source file:dev.ukanth.ufirewall.Api.java
@Deprecated private static List<Integer> getUidListFromPref(Context ctx, final String pks) { initSpecial();//www .jav a2 s .co m final PackageManager pm = ctx.getPackageManager(); final List<Integer> uids = new ArrayList<Integer>(); final StringTokenizer tok = new StringTokenizer(pks, "|"); while (tok.hasMoreTokens()) { final String pkg = tok.nextToken(); if (pkg != null && pkg.length() > 0) { try { if (pkg.startsWith("dev.afwall.special")) { uids.add(specialApps.get(pkg)); } else { uids.add(pm.getApplicationInfo(pkg, 0).uid); } } catch (Exception ex) { } } } Collections.sort(uids); return uids; }
From source file:net.kidlogger.kidlogger.KLService.java
private void doScanTask() { ActivityManager actMng = (ActivityManager) KLService.this.getSystemService(ACTIVITY_SERVICE); List<RunningTaskInfo> taskInfo = actMng.getRunningTasks(1); String packageName = taskInfo.get(0).topActivity.getPackageName(); if (!packageName.equalsIgnoreCase(prevPack)) { PackageManager pm = getPackageManager(); String currTask;/*www. jav a 2s. c om*/ //prevPack = packageName; prevPack = new String(packageName); try { CharSequence cs = pm .getApplicationLabel(pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA)); currTask = cs.toString(); } catch (Exception e) { currTask = "unknown"; } if (!currTask.equals("unknown")) { final String ct = new String(currTask); new Thread(new Runnable() { public void run() { sync.writeLog(".htm", Templates.getApiLog(ct)); } }).start(); //WriteThread wt = new WriteThread(sync, ".htm", Templates.getApiLog(currTask)); } } }
From source file:es.javocsoft.android.lib.toolbox.ToolBox.java
/** * gets the application icon.//from w w w . jav a 2 s.c o m * * @param context * @param packageName * @return */ public static Drawable appInfo_getIconFromPackageName(Context context, String packageName) { PackageManager pm = context.getPackageManager(); ApplicationInfo appInfo = null; try { appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA); } catch (NameNotFoundException e) { return null; } return appInfo.loadIcon(pm); }
From source file:com.linkbubble.Settings.java
public Drawable getConsumeBubbleIcon(Constant.BubbleAction action, boolean whiteShareIcon) { PackageManager packageManager = mContext.getPackageManager(); try {//from w ww . j a v a2 s.c o m String packageName = getConsumeBubblePackageName(action); String name = getConsumeBubbleActivityClassName(action); if (packageName != null && name != null) { if (name.equals(Constant.SHARE_PICKER_NAME)) { return mContext.getResources().getDrawable( whiteShareIcon ? R.drawable.ic_share_white_24dp : R.drawable.ic_share_grey600_24dp); } ComponentName componentName = new ComponentName(packageName, name); return packageManager.getActivityIcon(componentName); } else if (packageName != null) { // Try rendering the icon if we only have a packageName. ApplicationInfo app = packageManager.getApplicationInfo(packageName, 0); Drawable icon = packageManager.getApplicationIcon(app); return icon; } } catch (OutOfMemoryError ex) { } catch (PackageManager.NameNotFoundException e) { } return mContext.getResources().getDrawable(R.drawable.ic_launcher); }
From source file:dev.ukanth.ufirewall.Api.java
private static void updateRulesFromJson(Context ctx, JSONObject object, String preferenceName) throws JSONException { final StringBuilder wifi_uids = new StringBuilder(); final StringBuilder data_uids = new StringBuilder(); final StringBuilder roam_uids = new StringBuilder(); final StringBuilder vpn_uids = new StringBuilder(); final StringBuilder lan_uids = new StringBuilder(); Map<String, Object> json = JsonHelper.toMap(object); final PackageManager pm = ctx.getPackageManager(); for (Map.Entry<String, Object> entry : json.entrySet()) { String pkgName = entry.getKey(); if (pkgName.contains(":")) { pkgName = pkgName.split(":")[0]; }//from ww w .j a v a 2 s .co m JSONObject jsonObj = (JSONObject) JsonHelper.toJSON(entry.getValue()); Iterator<?> keys = jsonObj.keys(); while (keys.hasNext()) { //get wifi/data/lan etc String key = (String) keys.next(); switch (Integer.parseInt(key)) { case WIFI_EXPORT: if (wifi_uids.length() != 0) { wifi_uids.append('|'); } if (pkgName.startsWith("dev.afwall.special")) { wifi_uids.append(specialApps.get(pkgName)); } else { try { wifi_uids.append(pm.getApplicationInfo(pkgName, 0).uid); } catch (NameNotFoundException e) { } } break; case DATA_EXPORT: if (data_uids.length() != 0) { data_uids.append('|'); } if (pkgName.startsWith("dev.afwall.special")) { data_uids.append(specialApps.get(pkgName)); } else { try { data_uids.append(pm.getApplicationInfo(pkgName, 0).uid); } catch (NameNotFoundException e) { } } break; case ROAM_EXPORT: if (roam_uids.length() != 0) { roam_uids.append('|'); } if (pkgName.startsWith("dev.afwall.special")) { roam_uids.append(specialApps.get(pkgName)); } else { try { roam_uids.append(pm.getApplicationInfo(pkgName, 0).uid); } catch (NameNotFoundException e) { } } break; case VPN_EXPORT: if (vpn_uids.length() != 0) { vpn_uids.append('|'); } if (pkgName.startsWith("dev.afwall.special")) { vpn_uids.append(specialApps.get(pkgName)); } else { try { vpn_uids.append(pm.getApplicationInfo(pkgName, 0).uid); } catch (NameNotFoundException e) { } } break; case LAN_EXPORT: if (lan_uids.length() != 0) { lan_uids.append('|'); } if (pkgName.startsWith("dev.afwall.special")) { lan_uids.append(specialApps.get(pkgName)); } else { try { lan_uids.append(pm.getApplicationInfo(pkgName, 0).uid); } catch (NameNotFoundException e) { } } break; } } } final SharedPreferences prefs = ctx.getSharedPreferences(preferenceName, Context.MODE_PRIVATE); final Editor edit = prefs.edit(); edit.putString(PREF_WIFI_PKG_UIDS, wifi_uids.toString()); edit.putString(PREF_3G_PKG_UIDS, data_uids.toString()); edit.putString(PREF_ROAMING_PKG_UIDS, roam_uids.toString()); edit.putString(PREF_VPN_PKG_UIDS, vpn_uids.toString()); edit.putString(PREF_LAN_PKG_UIDS, lan_uids.toString()); edit.commit(); }