Last active
March 31, 2017 08:50
-
-
Save tseglevskiy/dc43de20efd261cfe895 to your computer and use it in GitHub Desktop.
Doze mode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if ( | |
connectivityManager.getActiveNetworkInfo() != null && | |
connectivityManager.getActiveNetworkInfo().isConnected() && | |
(!powerManager.isDeviceIdleMode() || | |
powerManager.isIgnoringBatteryOptimizations())) | |
{ | |
// do something | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
registerReceiver(br, | |
new IntentFilter( | |
PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Intent intent = new Intent(); | |
String packageName = getPackageName(); | |
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); | |
if (pm.isIgnoringBatteryOptimizations(packageName)) | |
// перейти к белому списку | |
intent.setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS); | |
else { | |
// запросить добавление в белый список | |
// если уже в белом списке, то ничего не произойдет | |
// !! требуется android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS | |
intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); | |
intent.setData(Uri.parse("package:" + packageName)); | |
} | |
startActivity(intent); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
// перейти к белому списку
intent.setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);