List of usage examples for android.content.pm PackageManager COMPONENT_ENABLED_STATE_ENABLED
int COMPONENT_ENABLED_STATE_ENABLED
To view the source code for android.content.pm PackageManager COMPONENT_ENABLED_STATE_ENABLED.
Click Source Link
From source file:de.ub0r.android.lib.DonationHelper.java
/** * Check if ads should be hidden./*from w w w . ja v a 2 s. c o m*/ * * @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:com.hamradiocoin.wallet.ui.RequestCoinsFragment.java
private void handleLocalApp() { final ComponentName component = new ComponentName(activity, SendCoinsActivity.class); final PackageManager pm = activity.getPackageManager(); final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(determineBitcoinRequestStr(false))); // launch intent chooser with ourselves excluded pm.setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); startActivity(intent);/* w w w . ja v a2s .c o m*/ pm.setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); activity.finish(); }
From source file:com.yacorso.nowaste.views.activities.DrawerActivity.java
/** * Enable every day local notification// www . j a v a2 s .c om */ private void enableNotificationReceiver() { Context context = getApplicationContext(); ComponentName receiver = new ComponentName(context, BootCompletedReceiver.class); PackageManager pm = context.getPackageManager(); pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); Intent serviceIntent = new Intent(context, NotificationService.class); context.stopService(serviceIntent); AlarmReceiver alarmReceiver = new AlarmReceiver(); alarmReceiver.setAlarm(context); }
From source file:android_network.hetnet.vpn_service.Util.java
public static boolean isEnabled(PackageInfo info, Context context) { int setting;/*from ww w . j a va2s.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); }
From source file:com.android.tv.TvApplication.java
/** * Checks the input counts and enable/disable TvActivity. Also updates the input list in * {@link SetupUtils}./*from ww w. j av a2 s . com*/ * * @param calledByTunerServiceChanged true if it is called when UsbTunerTvInputService * is enabled or disabled. * @param tunerServiceEnabled it's available only when calledByTunerServiceChanged is true. * @param dontKillApp when TvActivity is enabled or disabled by this method, the app restarts * by default. But, if dontKillApp is true, the app won't restart. */ public void handleInputCountChanged(boolean calledByTunerServiceChanged, boolean tunerServiceEnabled, boolean dontKillApp) { TvInputManager inputManager = (TvInputManager) getSystemService(Context.TV_INPUT_SERVICE); boolean enable = (calledByTunerServiceChanged && tunerServiceEnabled) || Features.UNHIDE.isEnabled(TvApplication.this); if (!enable) { List<TvInputInfo> inputs = inputManager.getTvInputList(); boolean skipTunerInputCheck = false; // Enable the TvActivity only if there is at least one tuner type input. if (!skipTunerInputCheck) { for (TvInputInfo input : inputs) { if (calledByTunerServiceChanged && !tunerServiceEnabled && UsbTunerTvInputService.getInputId(this).equals(input.getId())) { continue; } if (input.getType() == TvInputInfo.TYPE_TUNER) { enable = true; break; } } } if (DEBUG) Log.d(TAG, "Enable MainActivity: " + enable); } PackageManager packageManager = getPackageManager(); ComponentName name = new ComponentName(this, TvActivity.class); int newState = enable ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED; if (packageManager.getComponentEnabledSetting(name) != newState) { packageManager.setComponentEnabledSetting(name, newState, dontKillApp ? PackageManager.DONT_KILL_APP : 0); } SetupUtils.getInstance(TvApplication.this).onInputListUpdated(inputManager); }
From source file:com.cognizant.trumobi.em.Email.java
public static void setServicesEnabled(Context context, boolean enabled) { PackageManager pm = context.getPackageManager(); if (!enabled && pm.getComponentEnabledSetting(new ComponentName(context, EmMailService.class)) == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) { /*// w ww. j av a 2 s. co m * If no accounts now exist but the service is still enabled we're * about to disable it so we'll reschedule to kill off any existing * alarms. */ EmMailService.actionReschedule(context); } pm.setComponentEnabledSetting(new ComponentName(context, EmMessageCompose.class), enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); pm.setComponentEnabledSetting(new ComponentName(context, EmAccountShortcutPicker.class), enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); pm.setComponentEnabledSetting(new ComponentName(context, EmMailService.class), enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); if (enabled && pm.getComponentEnabledSetting(new ComponentName(context, EmMailService.class)) == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) { /* * And now if accounts do exist then we've just enabled the service * and we want to schedule alarms for the new accounts. */ EmMailService.actionReschedule(context); } }
From source file:com.google.android.apps.iosched.util.UIUtils.java
public static void enableDisableActivities(final Context context) { boolean isHoneycombTablet = isHoneycombTablet(context); PackageManager pm = context.getPackageManager(); // Enable/disable phone activities for (Class a : sPhoneActivities) { pm.setComponentEnabledSetting(new ComponentName(context, a), isHoneycombTablet ? PackageManager.COMPONENT_ENABLED_STATE_DISABLED : PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); }/*from ww w. j a v a2s . co m*/ // Enable/disable tablet activities for (Class a : sTabletActivities) { pm.setComponentEnabledSetting(new ComponentName(context, a), isHoneycombTablet ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); } }
From source file:com.android.settingslib.drawer.SettingsDrawerActivity.java
public void setTileEnabled(ComponentName component, boolean enabled) { PackageManager pm = getPackageManager(); int state = pm.getComponentEnabledSetting(component); boolean isEnabled = state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED; if (isEnabled != enabled || state == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) { if (enabled) { sTileBlacklist.remove(component); } else {/* w w w . j a v a 2 s . c om*/ sTileBlacklist.add(component); } pm.setComponentEnabledSetting(component, enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); new CategoriesUpdater().execute(); } }
From source file:com.kyleszombathy.sms_scheduler.MessageAlarmReceiver.java
/** Method to set a new alarm * @param context The app context//from w w w . j av a 2s . c o m * @param timeToSend The Time to send the message (in Calendar format) * @param phoneNumberList String Arraylist of phone numbers * @param messageContent The content of the message you want to send * @param alarmNumber Provide an identifier for the alarm * @param nameList The list of names, corresponding with the phone numbers*/ public void createAlarm(Context context, Calendar timeToSend, ArrayList<String> phoneNumberList, String messageContent, int alarmNumber, ArrayList<String> nameList) { this.context = context; // Creates new alarm alarm = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intentAlarm = new Intent(context, MessageAlarmReceiver.class); // Add extras Bundle extras = new Bundle(); extras.putStringArrayList("pNum", phoneNumberList); extras.putString("message", messageContent); extras.putInt("alarmNumber", alarmNumber); extras.putStringArrayList("nameList", nameList); intentAlarm.putExtras(extras); // Set alarm pendingIntent = PendingIntent.getBroadcast(context, alarmNumber, intentAlarm, PendingIntent.FLAG_UPDATE_CURRENT); alarm.set(AlarmManager.RTC_WAKEUP, timeToSend.getTimeInMillis(), pendingIntent); // Enable {@code MessageBootReceiver} to automatically restart the alarm when the // device is rebooted. ComponentName receiver = new ComponentName(context, MessageBootReceiver.class); PackageManager pm = context.getPackageManager(); pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); Log.i(TAG, "createAlarm: Alarm Created. alarmNumber: " + alarmNumber); }
From source file:org.hopestarter.wallet.ui.RequestCoinsFragment.java
private void handleLocalApp() { final ComponentName component = new ComponentName(activity, SendCoinsActivity.class); final PackageManager pm = activity.getPackageManager(); final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(determineBitcoinRequestStr(false))); try {/*from ww w.j a v a 2 s.c om*/ // launch intent chooser with ourselves excluded pm.setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); startActivity(intent); } catch (final ActivityNotFoundException x) { new Toast(activity).longToast(R.string.request_coins_no_local_app_msg); } finally { pm.setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); } activity.finish(); }