Java Code Examples for android.provider.Settings#ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS
The following examples show how to use
android.provider.Settings#ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FragmentSetup.java From FairEmail with GNU General Public License v3.0 | 5 votes |
@Override public void onResume() { super.onResume(); // Doze Boolean ignoring = true; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { Intent intent = new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS); PackageManager pm = getContext().getPackageManager(); if (intent.resolveActivity(pm) != null) { // system whitelisted ignoring = Helper.isIgnoringOptimizations(getContext()); if (ignoring == null) ignoring = true; } } btnDoze.setEnabled(!ignoring); // https://issuetracker.google.com/issues/37070074 //ignoring = (ignoring || Build.VERSION.SDK_INT != Build.VERSION_CODES.M); tvDozeDone.setText(ignoring ? R.string.title_setup_done : R.string.title_setup_to_do); tvDozeDone.setTextColor(ignoring ? textColorPrimary : colorWarning); tvDozeDone.setCompoundDrawablesWithIntrinsicBounds(ignoring ? check : null, null, null, null); // https://developer.android.com/training/basics/network-ops/data-saver.html if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { ConnectivityManager cm = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE); if (cm != null) { int status = cm.getRestrictBackgroundStatus(); grpDataSaver.setVisibility( status == ConnectivityManager.RESTRICT_BACKGROUND_STATUS_ENABLED ? View.VISIBLE : View.GONE); } } }
Example 2
Source File: MainActivity.java From TowerCollector with Mozilla Public License 2.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.M) private void startBatteryOptimizationsSystemActivity() { try { Intent intent = new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS); startActivityForResult(intent, BATTERY_OPTIMIZATIONS_ACTIVITY_RESULT); } catch (ActivityNotFoundException ex) { Timber.w(ex, "startBatteryOptimizationsSystemActivity(): Could not open Settings to change battery optimizations"); MyApplication.handleSilentException(ex); showCannotOpenAndroidSettingsDialog(); } }
Example 3
Source File: SettingsUtils.java From SmsCode with GNU General Public License v3.0 | 4 votes |
/** * Go to ignore battery optimization settings. */ @RequiresApi(api = Build.VERSION_CODES.M) public static void gotoIgnoreBatteryOptimizationSettings(Context context) { Intent intent = new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS); context.startActivity(intent); }
Example 4
Source File: SettingsUtils.java From XposedSmsCode with GNU General Public License v3.0 | 4 votes |
/** * Go to ignore battery optimization settings. */ @RequiresApi(api = Build.VERSION_CODES.M) public static void gotoIgnoreBatteryOptimizationSettings(Context context) { Intent intent = new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS); context.startActivity(intent); }
Example 5
Source File: IgnoreBatteryOptimizationNotification.java From PhoneProfilesPlus with Apache License 2.0 | 4 votes |
static private void showNotification(Context context, String title, String text) { String nTitle = title; String nText = text; if (Build.VERSION.SDK_INT < 24) { nTitle = context.getString(R.string.ppp_app_name); nText = title+": "+text; } PPApplication.createExclamationNotificationChannel(context); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, PPApplication.EXCLAMATION_NOTIFICATION_CHANNEL) .setColor(ContextCompat.getColor(context, R.color.notificationDecorationColor)) .setSmallIcon(R.drawable.ic_exclamation_notify) // notification icon .setContentTitle(nTitle) // title for notification .setContentText(nText) // message for notification .setAutoCancel(true); // clear notification after click mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(nText)); Intent intent = new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pi = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(pi); mBuilder.setPriority(NotificationCompat.PRIORITY_MAX); //if (android.os.Build.VERSION.SDK_INT >= 21) //{ mBuilder.setCategory(NotificationCompat.CATEGORY_RECOMMENDATION); mBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC); //} mBuilder.setOnlyAlertOnce(true); /* Intent disableIntent = new Intent(IGNORE_BATTERY_OPTIMIZATION_NOTIFICATION_DISABLE_ACTION); PendingIntent pDisableIntent = PendingIntent.getBroadcast(context, 0, disableIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Action.Builder actionBuilder = new NotificationCompat.Action.Builder( R.drawable.ic_action_exit_app_white, context.getString(R.string.ignore_battery_optimization_notification_disable_button), pDisableIntent); mBuilder.addAction(actionBuilder.build()); */ NotificationManagerCompat mNotificationManager = NotificationManagerCompat.from(context); try { mNotificationManager.notify( PPApplication.IGNORE_BATTERY_OPTIMIZATION_NOTIFICATION_TAG, PPApplication.IGNORE_BATTERY_OPTIMIZATION_NOTIFICATION_ID, mBuilder.build()); } catch (Exception e) { //Log.e("IgnoreBatteryOptimizationNotification.showNotification", Log.getStackTraceString(e)); PPApplication.recordException(e); } }
Example 6
Source File: DConnectUtil.java From DeviceConnect-Android with MIT License | 3 votes |
/** * Dozeモードの設定画面を開きます. * <p> * Dozeモードの解除には必ずユーザの許諾が必要になります。<br> * Android M 以前の OS の場合には、このメソッドは処理を行いません。 * </p> * * @param context コンテキスト */ public static void startDozeModeSettingActivity(final Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { Intent intent = new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); } }