List of usage examples for android.content.pm PackageManager DONT_KILL_APP
int DONT_KILL_APP
To view the source code for android.content.pm PackageManager DONT_KILL_APP.
Click Source Link
From source file:org.proninyaroslav.libretorrent.services.TorrentTaskService.java
@Override public void onCreate() { super.onCreate(); Log.i(TAG, "Start " + TorrentTaskService.class.getSimpleName()); notifyManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); repo = new TorrentStorage(getApplicationContext()); pref = new SettingsManager(getApplicationContext()); pref.registerOnTrayPreferenceChangeListener(this); ComponentName powerReceiver = new ComponentName(getApplicationContext(), PowerReceiver.class); getPackageManager().setComponentEnabledSetting(powerReceiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); if (pref.getBoolean(getString(R.string.pref_key_battery_control), false) && (Utils.getBatteryLevel(getApplicationContext()) <= Utils.getDefaultBatteryLowLevel())) { pauseTorrents.set(true);//from w w w. j av a 2 s . c o m } if (pref.getBoolean(getString(R.string.pref_key_download_and_upload_only_when_charging), false) && !Utils.isBatteryCharging(getApplicationContext())) { pauseTorrents.set(true); } if (pref.getBoolean(getString(R.string.pref_key_cpu_do_not_sleep), false)) { setKeepCpuAwake(true); } engineTask = new EngineTask(getApplicationContext(), this); exec.execute(engineTask); }
From source file:am.roadpolice.roadpolice.alarm.AlarmReceiver.java
@Override public void onReceive(Context context, Intent intent) { if (context == null || intent == null) { Logger.error("AlarmReceiver", "onReceive(Context " + (context == null ? "null," : ",") + " Intent " + (intent == null ? "null)" : ")")); return;/*w w w.j a v a2s .c om*/ } // Set Context mContext = context; // Get shared preferences. SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); // Check internet availability and only in that case start actions. final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); final boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting(); final String action = intent.getAction(); // Catch Network change state. if (!TextUtils.isEmpty(action) && action.equals("android.net.conn.CONNECTIVITY_CHANGE")) { // If internet connection established if (isConnected) { // If didn't missed last update of data due to network issues do nothing, // otherwise proceed with data updating. final boolean missUpdateDueToNetworkIssue = sp .getBoolean(MainActivity.MISS_UPDATE_DUE_TO_NETWORK_ISSUE, false); if (!missUpdateDueToNetworkIssue) return; } // If user switch off Internet connection do not proceed. else return; } // Check Boot state. else if (!TextUtils.isEmpty(action) && action.equals("android.intent.action.BOOT_COMPLETED")) { // Get stored alarm time. final long nextAlarmTime = PreferenceUtils.getDataLong(context, PreferenceUtils.KEY_ALERT_TIME_IN_MILLIS, -1); if (nextAlarmTime != -1) { // Set new alarm, as after reboot alarm was switched off. if (mAlarmManager == null) mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent alarmIntent = new Intent(context, AlarmReceiver.class); if (mAlarmIntent == null) mAlarmIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, 0); // Enable boot receiver ComponentName receiver = new ComponentName(context, AlarmReceiver.class); PackageManager pm = context.getPackageManager(); pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); final int ui = DialogSettings.getUpdateInterval(context); AlarmType type = ui == DialogSettings.DAILY ? AlarmType.DAILY : ui == DialogSettings.WEEKLY ? AlarmType.WEEKLY : AlarmType.MONTHLY; mAlarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, nextAlarmTime, type.getValue(), mAlarmIntent); } return; } // When alarm rise we appears in the block below. else { Logger.beep(); Logger.beep(); Logger.beep(); // Calculating next alarm time. final Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); final int updateInterval = DialogSettings.getUpdateInterval(context); if (updateInterval == DialogSettings.DAILY) calendar.add(Calendar.DATE, 1); else if (updateInterval == DialogSettings.WEEKLY) calendar.add(Calendar.DATE, 7); else if (updateInterval == DialogSettings.MONTHLY) calendar.add(Calendar.MONTH, 1); else Logger.error("AlarmReceiver", "Unknown Update Interval."); // Next alarm time. final long nextAlarmTimeInMillis = calendar.getTimeInMillis(); // Store next alarm time for further use. PreferenceUtils.storeDataLong(context, PreferenceUtils.KEY_ALERT_TIME_IN_MILLIS, nextAlarmTimeInMillis); } if (!isConnected) { Logger.debug("AlarmReceiver", "No Internet connection, while receiving Alarm message"); // If no internet connecting schedule data update, as soon // as internet connection will be available. SharedPreferences.Editor ed = sp.edit(); ed.putBoolean(MainActivity.MISS_UPDATE_DUE_TO_NETWORK_ISSUE, true); ed.apply(); return; } final String cerNum = sp.getString(MainActivity.CER_NUMBER, MainActivity.EMPTY_STRING); final String regNum = sp.getString(MainActivity.REG_NUMBER, MainActivity.EMPTY_STRING); final boolean login = sp.getBoolean(MainActivity.AUTO_LOGIN, false); if (!login) { // If no auto login user detected. Logger.debug("AlarmReceiver", "Why we enter this case if no auto login users detected?"); // Remove alarm. AlarmReceiver.createAlarm(context, AlarmReceiver.AlarmType.NONE); return; } if (TextUtils.isEmpty(cerNum) || TextUtils.isEmpty(regNum)) { Logger.debug("AlarmReceiver", "Why we enter this case if both data are null or empty?"); // Remove alarm. AlarmReceiver.createAlarm(context, AlarmReceiver.AlarmType.NONE); // Remove auto login. SharedPreferences.Editor ed = sp.edit(); ed.putBoolean(MainActivity.AUTO_LOGIN, false); ed.apply(); return; } // Start downloading data from internet. Submitter submitter = new Submitter(cerNum, regNum, this); submitter.executeOnExecutor(Executors.newSingleThreadExecutor()); }
From source file:com.android.transmart.PlaceActivity.java
@Override protected void onResume() { super.onResume(); // Commit shared preference that says we're in the foreground. prefsEditor.putBoolean(LocationConstants.EXTRA_KEY_IN_BACKGROUND, false); sharedPreferenceSaver.savePreferences(prefsEditor, false); // Disable the Manifest Checkin Receiver when the Activity is visible. // The Manifest Checkin Receiver is designed to run only when the Application // isn't active to notify the user of pending checkins that have succeeded // (usually through a Notification). // When the Activity is visible we capture checkins through the checkinReceiver. packageManager.setComponentEnabledSetting(newCheckinReceiverName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); // Register the checkinReceiver to listen for checkins while the Activity is visible. registerReceiver(checkinReceiver, newCheckinFilter); // Cancel notifications. notificationManager.cancel(LocationConstants.CHECKIN_NOTIFICATION); // Update the CheckinFragment with the last checkin. updateCheckinFragment(prefs.getString(LocationConstants.SP_KEY_LAST_CHECKIN_ID, null)); // Get the last known location (and optionally request location updates) and // update the place list. boolean followLocationChanges = prefs.getBoolean(LocationConstants.SP_KEY_FOLLOW_LOCATION_CHANGES, true); getLocationAndUpdatePlaces(followLocationChanges); }
From source file:tjs.tuneramblr.TuneramblrMobileActivity.java
@Override protected void onResume() { super.onResume(); // Commit shared preference that says we're in the foreground. prefsEditor.putBoolean(TuneramblrConstants.EXTRA_KEY_IN_BACKGROUND, false); sharedPreferenceSaver.savePreferences(prefsEditor, false); /*//from w w w. j a v a 2s. co m * Disable the Manifest Checkin Receiver when the Activity is visible. * The Manifest Checkin Receiver is designed to run only when the * Application isn't active to notify the user of pending checkins that * have succeeded (usually through a Notification). When the Activity is * visible we capture checkins through the checkinReceiver. */ packageManager.setComponentEnabledSetting(newCheckinReceiverName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); // Register the checkinReceiver to listen for checkins while the // Activity is visible. registerReceiver(checkinReceiver, newCheckinFilter); // update UI receiver registerReceiver(loginReceiver, new IntentFilter(LoginService.LOGGED_IN)); // Cancel notifications. notificationManager.cancel(TuneramblrConstants.CHECKIN_NOTIFICATION); // Get the last known location (and optionally request location updates) // and // update the place list. boolean followLocationChanges = prefs.getBoolean(TuneramblrConstants.SP_KEY_FOLLOW_LOCATION_CHANGES, true); getLocationAndUpdatePlaces(followLocationChanges); }
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.radioactiveyak.location_best_practices.UI.PlaceActivity.java
@Override protected void onResume() { super.onResume(); // Commit shared preference that says we're in the foreground. prefsEditor.putBoolean(PlacesConstants.EXTRA_KEY_IN_BACKGROUND, false); sharedPreferenceSaver.savePreferences(prefsEditor, false); // Disable the Manifest Checkin Receiver when the Activity is visible. // The Manifest Checkin Receiver is designed to run only when the Application // isn't active to notify the user of pending checkins that have succeeded // (usually through a Notification). // When the Activity is visible we capture checkins through the checkinReceiver. packageManager.setComponentEnabledSetting(newCheckinReceiverName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); // Register the checkinReceiver to listen for checkins while the Activity is visible. registerReceiver(checkinReceiver, newCheckinFilter); // Cancel notifications. notificationManager.cancel(PlacesConstants.CHECKIN_NOTIFICATION); // Update the CheckinFragment with the last checkin. updateCheckinFragment(prefs.getString(PlacesConstants.SP_KEY_LAST_CHECKIN_ID, null)); // Get the last known location (and optionally request location updates) and // update the place list. boolean followLocationChanges = prefs.getBoolean(PlacesConstants.SP_KEY_FOLLOW_LOCATION_CHANGES, true); getLocationAndUpdatePlaces(followLocationChanges); }
From source file:com.p3authentication.preferences.Prefs.java
protected void hideLauncherIcon() { // TODO Auto-generated method stub AlertDialog.Builder builder = new AlertDialog.Builder(Prefs.this); builder.setTitle("Important!"); builder.setMessage(/* www. ja v a2 s .c o m*/ "To launch P3 again, dial " + AccessPin.getText().toString() + " or set up your custom Pin below."); builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Prefs.this.getPackageManager().setComponentEnabledSetting(LAUNCHER_COMPONENT_NAME, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); } }); builder.setIcon(android.R.drawable.ic_dialog_alert); builder.show(); ComponentName receiver = new ComponentName(Prefs.this, NumberListerner.class); PackageManager pm = Prefs.this.getPackageManager(); pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); AccessPin.setEnabled(true); }
From source file:de.Maxr1998.xposed.maxlock.ui.settings.SettingsFragment.java
@Override public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { super.onPreferenceTreeClick(preferenceScreen, preference); if (preference == findPreference(Common.LOCKING_TYPE_SETTINGS)) { launchFragment(new LockingTypeSettingsFragment(), true, this); return true; } else if (preference == findPreference(Common.LOCKING_UI_SETTINGS)) { launchFragment(new LockingUISettingsFragment(), true, this); return true; } else if (preference == findPreference(Common.LOCKING_OPTIONS)) { PREFS.edit().putBoolean(Common.ENABLE_LOGGING, PREFS.getBoolean(Common.ENABLE_PRO, false)).apply(); launchFragment(new LockingOptionsFragment(), true, this); return true; } else if (preference == findPreference(Common.IIMOD_OPTIONS)) { // Setup remain timer long timer = PREFS.getInt(Common.IMOD_DELAY_GLOBAL, 600000) - (System.currentTimeMillis() - PREFS.getLong(Common.IMOD_LAST_UNLOCK_GLOBAL, 0)); if (timer < 0) { timer = 0L;//from w ww .ja va2 s . c o m } PREFS.edit().putInt(Common.IMOD_REMAIN_TIMER_GLOBAL, (int) timer).apply(); launchFragment(new LockingIntikaFragment(), true, this); return true; } else if (preference == findPreference(Common.CHOOSE_APPS)) { launchFragment(new AppListFragment(), true, this); return true; } else if (preference == findPreference(Common.HIDE_APP_FROM_LAUNCHER) && preference instanceof CheckBoxPreference) { CheckBoxPreference hideApp = (CheckBoxPreference) preference; if (hideApp.isChecked()) { Toast.makeText(getActivity(), R.string.reboot_required, Toast.LENGTH_SHORT).show(); ComponentName componentName = new ComponentName(getActivity(), "de.Maxr1998.xposed.maxlock.Main"); getActivity().getPackageManager().setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); } else { ComponentName componentName = new ComponentName(getActivity(), "de.Maxr1998.xposed.maxlock.Main"); getActivity().getPackageManager().setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); } } else if (preference == findPreference(Common.USE_DARK_STYLE) || preference == findPreference(Common.ENABLE_PRO)) { ((SettingsActivity) getActivity()).restart(); return true; } else if (preference == findPreference(Common.UNINSTALL)) { if (!isDeviceAdminActive()) { Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN); intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, deviceAdmin); startActivity(intent); } else { devicePolicyManager.removeActiveAdmin(deviceAdmin); } return true; } return false; }
From source file:org.ametro.app.ApplicationEx.java
public void changeNetworkStateReceiverState(boolean enabled) { PackageManager manager = getPackageManager(); ComponentName name = new ComponentName(this, NetworkStateReceiver.class); int state = enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED; manager.setComponentEnabledSetting(name, state, PackageManager.DONT_KILL_APP); }
From source file:org.proninyaroslav.libretorrent.services.TorrentTaskService.java
@Override public void onDestroy() { super.onDestroy(); setKeepCpuAwake(false);/*from w w w . j ava 2 s. c om*/ /* Handles must be destructed before the session is destructed */ torrentTasks.clear(); if (engineTask != null) { engineTask.cancel(); } ComponentName powerReceiver = new ComponentName(getApplicationContext(), PowerReceiver.class); getPackageManager().setComponentEnabledSetting(powerReceiver, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); isAlreadyRunning = false; repo = null; pref.unregisterOnTrayPreferenceChangeListener(this); pref = null; Log.i(TAG, "Stop " + TorrentTaskService.class.getSimpleName()); }