List of usage examples for android.content.pm PackageManager COMPONENT_ENABLED_STATE_DEFAULT
int COMPONENT_ENABLED_STATE_DEFAULT
To view the source code for android.content.pm PackageManager COMPONENT_ENABLED_STATE_DEFAULT.
Click Source Link
From source file:Main.java
public static int getVersionCode(Context context) { PackageManager pm = context.getPackageManager(); int versionCode = 1; try {/*from w ww .ja va2s . c o m*/ PackageInfo info = pm.getPackageInfo(context.getPackageName(), PackageManager.COMPONENT_ENABLED_STATE_DEFAULT); if (null != info) { versionCode = info.versionCode; } } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return versionCode; }
From source file:Main.java
public static String getVersionName(Context context) { PackageManager pm = context.getPackageManager(); String versionName = ""; try {/*from w w w. ja va 2 s . c o m*/ PackageInfo info = pm.getPackageInfo(context.getPackageName(), PackageManager.COMPONENT_ENABLED_STATE_DEFAULT); if (null != info) { versionName = info.versionName; } } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return versionName; }
From source file:Main.java
public static List<ResolveInfo> getShareTargets(Context ctx) { Intent intent = new Intent(Intent.ACTION_SEND, null); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.setType("text/plain"); PackageManager pm = ctx.getPackageManager(); return pm.queryIntentActivities(intent, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT); }
From source file:com.github.michalbednarski.intentslab.editor.ComponentPickerDialogFragment.java
private static boolean isComponentEnabled(PackageManager pm, ResolveInfo info) { final boolean defaultEnabled; final ComponentName componentName; ActivityInfo activityInfo = info.activityInfo; if (activityInfo != null) { if (!activityInfo.applicationInfo.enabled) { return false; }//from www .j ava 2 s . c om defaultEnabled = activityInfo.enabled; componentName = new ComponentName(activityInfo.packageName, activityInfo.name); } else { ServiceInfo serviceInfo = info.serviceInfo; if (!serviceInfo.applicationInfo.enabled) { return false; } defaultEnabled = serviceInfo.enabled; componentName = new ComponentName(serviceInfo.packageName, serviceInfo.name); } int enabledSetting = pm.getComponentEnabledSetting(componentName); if (enabledSetting == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) { return defaultEnabled; } else { return enabledSetting != PackageManager.COMPONENT_ENABLED_STATE_DISABLED; } }
From source file:edu.mit.mobile.android.demomode.Preferences.java
private void updateDemoModeEnabled() { getPackageManager().setComponentEnabledSetting(new ComponentName(this, DemoMode.class), mPrefs.getBoolean(KEY_ENABLED, true) ? PackageManager.COMPONENT_ENABLED_STATE_DEFAULT : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); }
From source file:com.github.michalbednarski.intentslab.browser.ComponentInfoFragment.java
@SuppressLint("InlinedApi") public static boolean isComponentDisabledState(int state, boolean defaultEnabled) { return state == PackageManager.COMPONENT_ENABLED_STATE_DISABLED || state == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER || (state == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT && !defaultEnabled); }
From source file:org.site_monitor.activity.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_refresh) { if (BuildConfig.DEBUG) { Log.i(TAG, "global refresh requested"); }//from w w w. ja va 2 s . com NetworkService.enqueueCheckSitesWork(this); return true; } if (id == R.id.action_settings) { PrefSettingsActivity.start(context); return true; } if (id == R.id.action_about) { AboutActivity.start(context); return true; } if (id == R.id.action_inject) { try { DummySiteInjector.inject(this.getCurrentFocus(), taskFragment, dbHelper.getDBSiteSettings()); loadSiteSettingsBusinesses(); alarmUtil.startAlarmIfNeeded(context); } catch (SQLException e) { Log.e(TAG, "dummyinject", e); } return true; } if (id == R.id.action_debug) { StringBuilder sb = new StringBuilder("you're on alpha version").append("\n"); sb.append("Connectivity: ").append(ConnectivityUtil.isConnected(context)).append("\n"); int startupBootState = context.getPackageManager() .getComponentEnabledSetting(new ComponentName(context, StartupBootReceiver.class)); boolean startupBootEnable = (startupBootState == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT || startupBootState == PackageManager.COMPONENT_ENABLED_STATE_ENABLED); sb.append("StartupBoot state: ").append(startupBootEnable).append("\n"); sb.append("Alarm set: ").append(alarmUtil.getCurrentInterval()).append("\n"); sb.append("Battery: ").append(BatteryLevelReceiver.getLastAction()).append("\n"); Toast.makeText(this, sb.toString(), Toast.LENGTH_LONG).show(); return true; } return super.onOptionsItemSelected(item); }
From source file:de.ub0r.android.lib.DonationHelper.java
/** * Check if ads should be hidden./* w w w . ja v a2 s . c om*/ * * @param context * {@link Context} * @return true if ads should be hidden */ public static boolean hideAds(final Context context) { PackageManager pm = context.getPackageManager(); Intent donationCheck = new Intent(DONATOR_BROADCAST_CHECK); ResolveInfo ri = pm.resolveService(donationCheck, 0); // Log.d(TAG, "ri: " + ri); int match = PackageManager.SIGNATURE_UNKNOWN_PACKAGE; if (ri != null) { Log.d(TAG, "found package: " + ri.serviceInfo.packageName); ComponentName cn = new ComponentName(ri.serviceInfo.packageName, ri.serviceInfo.name); // Log.d(TAG, "component name: " + cn); int i = pm.getComponentEnabledSetting(cn); // Log.d(TAG, "component status: " + i); // Log.d(TAG, "package status: " + ri.serviceInfo.enabled); if (i == PackageManager.COMPONENT_ENABLED_STATE_ENABLED || i == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT && ri.serviceInfo.enabled) { match = pm.checkSignatures(context.getPackageName(), ri.serviceInfo.packageName); } else { Log.w(TAG, ri.serviceInfo.packageName + ": " + ri.serviceInfo.enabled); } } Log.i(TAG, "signature match: " + match); if (match != PackageManager.SIGNATURE_UNKNOWN_PACKAGE) { if (Math.random() < CHECK_DONATOR_LIC) { // verify donator license ComponentName cn = context.startService(donationCheck); Log.d(TAG, "Started service: " + cn); if (cn == null) { return false; } } return match == PackageManager.SIGNATURE_MATCH; } pm = null; // no donator app installed, check donation traditionally // do not drop legacy donators boolean ret = PreferenceManager.getDefaultSharedPreferences(context).getBoolean(PREFS_HIDEADS, false); Log.d(TAG, "legacy donation check: " + ret); return ret; }
From source file:android_network.hetnet.vpn_service.Util.java
public static boolean isEnabled(PackageInfo info, Context context) { int setting;/*from ww w. ja v a 2 s. co m*/ try { PackageManager pm = context.getPackageManager(); setting = pm.getApplicationEnabledSetting(info.packageName); } catch (IllegalArgumentException ex) { setting = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT; Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } if (setting == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) return info.applicationInfo.enabled; else return (setting == PackageManager.COMPONENT_ENABLED_STATE_ENABLED); }