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:damo.three.ie.prepay.ConnectivityReceiver.java
/** * Enables ConnectivityReceiver//from ww w .ja v a 2 s. c om */ public static void enableReceiver(Context context) { ComponentName component = new ComponentName(context, ConnectivityReceiver.class); context.getPackageManager().setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); }
From source file:net.eledge.android.europeana.service.receiver.BlogCheckerReceiver.java
public void enableBlogChecker(Context context) { alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(context, BlogCheckerReceiver.class); blogCheckerIntent = PendingIntent.getBroadcast(context, 0, intent, 0); alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, INTERVAL, INTERVAL, blogCheckerIntent);/*from w w w. j av a2s . c o m*/ ComponentName receiver = new ComponentName(context, BootReceiver.class); PackageManager pm = context.getPackageManager(); if (pm != null) { pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); } }
From source file:uk.co.ashtonbrsc.intentexplode.Settings.java
public boolean onPreferenceChange(Preference preference, Object newValue) { if (preference == interceptEnabledPreference) { Boolean enabled = (Boolean) newValue; int flag = (enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED); ComponentName component = new ComponentName(Settings.this, Explode.class); getPackageManager().setComponentEnabledSetting(component, flag, PackageManager.DONT_KILL_APP); }/*from w w w . j av a 2 s. c o m*/ return true; }
From source file:com.tonikorin.cordova.plugin.autostart.AutoStart.java
private void setAutoStart(boolean enabled) { Context context = cordova.getActivity().getApplicationContext(); int componentState; SharedPreferences sp = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE); SharedPreferences.Editor editor = sp.edit(); if (enabled) { componentState = PackageManager.COMPONENT_ENABLED_STATE_ENABLED; // Store the class name of your main activity for AppStarter editor.putString(CLASS_NAME, cordova.getActivity().getLocalClassName()); } else {//from w ww . ja v a 2 s. c o m componentState = PackageManager.COMPONENT_ENABLED_STATE_DISABLED; editor.remove(CLASS_NAME); } editor.commit(); // Enable or Disable BootCompletedReceiver ComponentName bootCompletedReceiver = new ComponentName(context, BootCompletedReceiver.class); PackageManager pm = context.getPackageManager(); pm.setComponentEnabledSetting(bootCompletedReceiver, componentState, PackageManager.DONT_KILL_APP); }
From source file:com.example.android.powerreceiver.MainActivity.java
@Override protected void onStart() { //Enable the broadcast receiver when the app is visible mPackageManager.setComponentEnabledSetting(mReceiverComponentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); super.onStart(); }
From source file:com.android.tv.receiver.BootCompletedReceiver.java
@Override public void onReceive(Context context, Intent intent) { if (DEBUG)/*from w w w.j a v a 2 s . c om*/ Log.d(TAG, "boot completed " + intent); // Start {@link NotificationService}. Intent notificationIntent = new Intent(context, NotificationService.class); notificationIntent.setAction(NotificationService.ACTION_SHOW_RECOMMENDATION); context.startService(notificationIntent); // Grant permission to already set up packages after the system has finished booting. SetupUtils.grantEpgPermissionToSetUpPackages(context); if (Features.UNHIDE.isEnabled(context)) { if (OnboardingUtils.isFirstBoot(context)) { // Enable the application if this is the first "unhide" feature is enabled just in // case when the app has been disabled before. PackageManager pm = context.getPackageManager(); ComponentName name = new ComponentName(context, TvActivity.class); if (pm.getComponentEnabledSetting(name) != PackageManager.COMPONENT_ENABLED_STATE_ENABLED) { pm.setComponentEnabledSetting(name, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, 0); } OnboardingUtils.setFirstBootCompleted(context); } } if (CommonFeatures.DVR.isEnabled(context) && BuildCompat.isAtLeastN()) { DvrRecordingService.startService(context); } }
From source file:com.doctoror.surprise.SurpriseActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); mFragmentTransactionsAllowed = true; setContentView(R.layout.activity_surprise); mLocalBroadcastManager = LocalBroadcastManager.getInstance(this); mLocalBroadcastManager.registerReceiver(mServiceReceiver, mServiceReceiver.mIntentFilter); mAnimatorSurprise = (ViewAnimator) findViewById(R.id.animator_surprise); mAnimatorUpgrade = (ViewAnimator) findViewById(R.id.animator_upgrade); mPackageManager = getPackageManager(); mReceiverComponent = new ComponentName(this, SurpriseReceiver.class); final CompoundButton surprise = (CompoundButton) findViewById(R.id.btn_surprise); surprise.setChecked(mPackageManager/*w w w.ja v a 2s . co m*/ .getComponentEnabledSetting(mReceiverComponent) == PackageManager.COMPONENT_ENABLED_STATE_ENABLED); surprise.setOnCheckedChangeListener(this); findViewById(R.id.btn_surprise_to_su).setOnClickListener(this); findViewById(R.id.info_surprise).setOnClickListener(this); findViewById(R.id.info_upgrade).setOnClickListener(this); }
From source file:me.myatminsoe.myansms.SMSdroid.java
@Override public void onCreate() { try {// w w w. jav a 2 s.co m Class.forName("android.os.AsyncTask"); } catch (Throwable ignore) { } super.onCreate(); Log.i(TAG, "init SMSdroid v" + BuildConfig.VERSION_NAME + " (" + BuildConfig.VERSION_CODE + ")"); // check for default app only when READ_SMS was granted // this may need a second launch on Android 6.0 though if (hasPermission(this, Manifest.permission.READ_SMS)) { final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(this); int state = PackageManager.COMPONENT_ENABLED_STATE_DISABLED; if (p.getBoolean(PreferencesActivity.PREFS_ACTIVATE_SENDER, true)) { try { Cursor c = getContentResolver().query(SenderActivity.URI_SENT, PROJECTION, null, null, "_id LIMIT 1"); if (c == null) { Log.i(TAG, "disable .Sender: cursor=null"); } else if (SmsManager.getDefault() == null) { Log.i(TAG, "disable .Sender: SmsManager=null"); } else { state = PackageManager.COMPONENT_ENABLED_STATE_ENABLED; Log.d(TAG, "enable .Sender"); } if (c != null && !c.isClosed()) { c.close(); } } catch (IllegalArgumentException | SQLiteException e) { } } else { Log.i(TAG, "disable .Sender"); } getPackageManager().setComponentEnabledSetting(new ComponentName(this, SenderActivity.class), state, PackageManager.DONT_KILL_APP); } else { Log.w(TAG, "ignore .Sender state, READ_SMS permission is missing to check default app"); } }
From source file:de.ub0r.android.smsdroid.SMSdroid.java
@Override public void onCreate() { try {/*w w w . j av a2s. c o m*/ Class.forName("android.os.AsyncTask"); } catch (Throwable ignore) { } super.onCreate(); Log.i(TAG, "init SMSdroid v" + BuildConfig.VERSION_NAME + " (" + BuildConfig.VERSION_CODE + ")"); // check for default app only when READ_SMS was granted // this may need a second launch on Android 6.0 though if (hasPermission(this, Manifest.permission.READ_SMS)) { final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(this); int state = PackageManager.COMPONENT_ENABLED_STATE_DISABLED; if (p.getBoolean(PreferencesActivity.PREFS_ACTIVATE_SENDER, true)) { try { Cursor c = getContentResolver().query(SenderActivity.URI_SENT, PROJECTION, null, null, "_id LIMIT 1"); if (c == null) { Log.i(TAG, "disable .Sender: cursor=null"); } else if (SmsManager.getDefault() == null) { Log.i(TAG, "disable .Sender: SmsManager=null"); } else { state = PackageManager.COMPONENT_ENABLED_STATE_ENABLED; Log.d(TAG, "enable .Sender"); } if (c != null && !c.isClosed()) { c.close(); } } catch (IllegalArgumentException | SQLiteException e) { Log.e(TAG, "disable .Sender: ", e.getMessage(), e); } } else { Log.i(TAG, "disable .Sender"); } getPackageManager().setComponentEnabledSetting(new ComponentName(this, SenderActivity.class), state, PackageManager.DONT_KILL_APP); } else { Log.w(TAG, "ignore .Sender state, READ_SMS permission is missing to check default app"); } }
From source file:org.ounl.lifelonglearninghub.nfcecology.scheduler.SampleAlarmReceiver.java
/** * Sets an alarm//ww w. j a v a 2 s . com * @param context */ public void setAlarm(Context context) { Log.d(CLASSNAME, "setAlarm"); alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(context, SampleAlarmReceiver.class); alarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); calendar.add(Calendar.MINUTE, iMinsss); Log.d(CLASSNAME, "Setting alarm at " + calendar.getTime()); alarmMgr.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), alarmIntent); ComponentName receiver = new ComponentName(context, SampleBootReceiver.class); PackageManager pm = context.getPackageManager(); pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); }