public static void updateMenuEntries(Context context, Menu menu, String pkgName) { if (context.getPackageManager().getLaunchIntentForPackage(pkgName) == null) { menu.findItem(R.id.menu_app_launch).setEnabled(false); Drawable icon = menu.findItem(R.id.menu_app_launch).getIcon().mutate(); icon.setColorFilter(Color.GRAY, Mode.SRC_IN); menu.findItem(R.id.menu_app_launch).setIcon(icon); } boolean hasMarketLink = false; try { PackageManager pm = context.getPackageManager(); String installer = pm.getInstallerPackageName(pkgName); if (installer != null) hasMarketLink = installer.equals("com.android.vending") || installer.contains("google"); } catch (Exception e) { } menu.findItem(R.id.menu_app_store).setEnabled(hasMarketLink); try { Resources res = context.createPackageContext("com.android.vending", 0).getResources(); int id = res.getIdentifier("ic_launcher_play_store", "mipmap", "com.android.vending"); Drawable icon = res.getDrawable(id); if (!hasMarketLink) { icon = icon.mutate(); icon.setColorFilter(Color.GRAY, Mode.SRC_IN); } menu.findItem(R.id.menu_app_store).setIcon(icon); } catch (Exception e) { } }
public static ComponentName getErrorReportReceiver( Context context, String packageName, int appFlags) { // check if error reporting is enabled in secure settings int enabled = Settings.Secure.getInt( context.getContentResolver(), Settings.Secure.SEND_ACTION_APP_ERROR, 0); if (enabled == 0) { return null; } PackageManager pm = context.getPackageManager(); // look for receiver in the installer package String candidate = pm.getInstallerPackageName(packageName); ComponentName result = getErrorReportReceiver(pm, packageName, candidate); if (result != null) { return result; } // if the error app is on the system image, look for system apps // error receiver if ((appFlags & ApplicationInfo.FLAG_SYSTEM) != 0) { candidate = SystemProperties.get(SYSTEM_APPS_ERROR_RECEIVER_PROPERTY); result = getErrorReportReceiver(pm, packageName, candidate); if (result != null) { return result; } } // if there is a default receiver, try that candidate = SystemProperties.get(DEFAULT_ERROR_RECEIVER_PROPERTY); return getErrorReportReceiver(pm, packageName, candidate); }
public static final boolean isPackageInstalled(Context context, String packageName) { PackageManager pm = context.getPackageManager(); try { pm.getPackageInfo(packageName, PackageManager.GET_META_DATA); return "com.android.vending".equals(pm.getInstallerPackageName(packageName)); } catch (NameNotFoundException e) { return false; } }
public static boolean hasMarketLink(Context context, String packageName) { try { PackageManager pm = context.getPackageManager(); String installer = pm.getInstallerPackageName(packageName); if (installer != null) return installer.equals("com.android.vending") || installer.contains("google"); } catch (Exception ex) { log(null, Log.WARN, ex.toString()); } return false; }
/** Returns true only if actual installer for specified app */ @Override public boolean isPackageInstaller(final String packageName) { Logger.d("sPackageInstaller: packageName = ", packageName); final PackageManager packageManager = context.getPackageManager(); final String installerPackageName = packageManager.getInstallerPackageName(packageName); Logger.d("installerPackageName = ", installerPackageName); return NOKIA_INSTALLER.equals(installerPackageName); }