Java Code Examples for android.provider.Settings#ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
The following examples show how to use
android.provider.Settings#ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS .
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: SystemUtil.java From MyBookshelf with GNU General Public License v3.0 | 8 votes |
public static void ignoreBatteryOptimization(Activity activity) { if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.M) return; PowerManager powerManager = (PowerManager) activity.getSystemService(POWER_SERVICE); boolean hasIgnored = powerManager.isIgnoringBatteryOptimizations(activity.getPackageName()); // 判断当前APP是否有加入电池优化的白名单,如果没有,弹出加入电池优化的白名单的设置对话框。 if (!hasIgnored) { try { @SuppressLint("BatteryLife") Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); intent.setData(Uri.parse("package:" + activity.getPackageName())); activity.startActivity(intent); } catch (Throwable ignored) { } } }
Example 2
Source File: SystemUtil.java From a with GNU General Public License v3.0 | 6 votes |
public static void ignoreBatteryOptimization(Activity activity) { if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.M) return; PowerManager powerManager = (PowerManager) activity.getSystemService(POWER_SERVICE); boolean hasIgnored = powerManager.isIgnoringBatteryOptimizations(activity.getPackageName()); // 判断当前APP是否有加入电池优化的白名单,如果没有,弹出加入电池优化的白名单的设置对话框。 if (!hasIgnored) { try { @SuppressLint("BatteryLife") Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); intent.setData(Uri.parse("package:" + activity.getPackageName())); activity.startActivity(intent); } catch (Throwable ignored) { } } }
Example 3
Source File: SetupActivity.java From SightRemote with GNU General Public License v3.0 | 6 votes |
@Override public void onClick(View v) { if (v == proceed) { if (agree.isChecked()) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { viewPager.setCurrentItem(1); PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE); if (!powerManager.isIgnoringBatteryOptimizations(getPackageName())) { Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); intent.setData(Uri.parse("package:" + getPackageName())); startActivity(intent); } else { viewPager.setCurrentItem(2); startBluetoothScan(); } } else { viewPager.setCurrentItem(2); startBluetoothScan(); } } else Toast.makeText(this, R.string.accept_terms, Toast.LENGTH_SHORT).show(); } else if (v == closeWizard) { startActivity(new Intent(this, StatusActivity.class)); finish(); } }
Example 4
Source File: SettingsUtils.java From SmsCode with GNU General Public License v3.0 | 5 votes |
/** * Request ignore battery optimization */ @RequiresApi(api = Build.VERSION_CODES.M) @SuppressLint("BatteryLife") public static void requestIgnoreBatteryOptimization(Context context) { Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); intent.setData(Uri.parse("package:" + BuildConfig.APPLICATION_ID)); context.startActivity(intent); }
Example 5
Source File: SettingsUtils.java From XposedSmsCode with GNU General Public License v3.0 | 5 votes |
/** * Request ignore battery optimization */ @RequiresApi(api = Build.VERSION_CODES.M) @SuppressLint("BatteryLife") public static void requestIgnoreBatteryOptimization(Context context) { Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); intent.setData(Uri.parse("package:" + BuildConfig.APPLICATION_ID)); context.startActivity(intent); }
Example 6
Source File: SettingsWindow.java From NetCloud_android with GNU General Public License v2.0 | 5 votes |
@Override public void onClick(View v) { if(v.getTag() instanceof Integer){ int settingID = (int)v.getTag(); switch (settingID){ case SETTING_APPS_UNDER_CTRL:{ MsgDispatcher.get().dispatchSync(Messege.PUSH_WINDOW, TrafficCtrlWindow.createWindow(getContext(), VpnConfig.CTRL_BITS.BASE)); break; } case SETTING_DNS_SERVER:{ showDnsConfigDialog(); break; } case SETTING_PROXY_ADDR:{ showProxyConfigDialog(); break; } case SETTING_CRASH_RECORDS:{ MsgDispatcher.get().dispatchSync(Messege.PUSH_WINDOW, new CrashRecordWindow(ContextMgr.getContext())); break; }case SETTING_ABOUT:{ Toast.makeText(getContext(), ResTools.getString(R.string.app_name) + " " + SystemUtils.getLocalVersionName(getContext()) , Toast.LENGTH_SHORT).show(); break; }case SETTING_ENHANCE_BACKGROUN_RUNNING:{ final Intent doze = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); doze.setData(Uri.parse("package:" + getContext().getPackageName())); if(getContext().getPackageManager().resolveActivity(doze, 0) != null){ getContext().startActivity(doze); }else{ Toast.makeText(getContext(), R.string.tips_devices_not_available, Toast.LENGTH_SHORT).show(); } break; } } } }
Example 7
Source File: IntentHelper.java From GeometricWeather with GNU Lesser General Public License v3.0 | 5 votes |
@RequiresApi(api = Build.VERSION_CODES.M) @SuppressLint("BatteryLife") public static void startBatteryOptimizationActivity(GeoActivity activity) { Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); intent.setData(Uri.parse("package:" + activity.getPackageName())); if (isIntentAvailable(activity, intent)) { activity.startActivity(intent); } else { SnackbarUtils.showSnackbar(activity, "Unavailable battery optimization activity."); } }
Example 8
Source File: Conditions.java From android_packages_apps_GmsCore with Apache License 2.0 | 5 votes |
@Override public void onClick(View v) { if (SDK_INT < 23) return; Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); intent.setData(Uri.parse("package:" + v.getContext().getPackageName())); v.getContext().startActivity(intent); }
Example 9
Source File: SystemChecks.java From android_packages_apps_GmsCore with Apache License 2.0 | 4 votes |
@Override public void tryResolve(Fragment fragment) { Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); intent.setData(Uri.parse("package:" + fragment.getActivity().getPackageName())); fragment.startActivityForResult(intent, REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); }
Example 10
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 startConfirmIgnoreDozeMode(final Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); intent.setData(Uri.parse("package:" + context.getPackageName())); context.startActivity(intent); } }