android - REQUEST_IGNORE_BATTERY_OPTIMIZATIONS how to do it right -
i have intentservice task in foreground mode, in android m+ task stops in doze mode. read google banned if app uses intent set themself in whitelist. if use permission , check grant or denied, granted result, nothing happen. don't see app in whitelist. how can add app in whitelist without banned? (i added permission in manifest)
if(build.version.sdk_int>=23){ int permissioncheck= contextcompat .checkselfpermission(this, manifest.permission.request_ignore_battery_optimizations); if(permissioncheck == packagemanager.permission_denied){ //should show explanation if(activitycompat.shouldshowrequestpermissionrationale (this, manifest.permission.request_ignore_battery_optimizations)){ //show explanation final string message = ""; snackbar.make(coordinatorlayoutview,message,snackbar.length_long) .setaction("grant", new view.onclicklistener() { @override public void onclick(view v) { activitycompat.requestpermissions(mainactivity.this, new string[]{manifest.permission.request_ignore_battery_optimizations},permission_request_code); } }) .show(); }else{ //no explanation need,we can request permission activitycompat.requestpermissions(this, new string[]{manifest.permission.request_ignore_battery_optimizations},permission_request_code); } } }
request_ignore_battery_optimizations
not dangerous
permission. not need, or want, of code. quoting the documentation request_ignore_battery_optimizations
:
permission application must hold in order use action_request_ignore_battery_optimizations. normal permission: app requesting granted permission, without user needing approve or see it.
so, delete code.
i don't see app in whitelist.
that because user did not add whitelist, apparently.
requesting request_ignore_battery_optimizations
grants authority, security standpoint, start activity an action_request_ignore_battery_optimizations
intent
. sure include app's package uri
:
startactivity(new intent(settings.action_request_ignore_battery_optimizations, uri.parse("package:"+getpackagename())));
the user taken screen can indicate willing suspend portions of doze mode effects on app.
how can add app in whitelist without banned?
if not want banned, not of this. have in app starts activity an action_ignore_battery_optimization_settings
intent
. leads user overall list of apps, user can toggle ones , not on whitelist. not require permission.
the act of requesting request_ignore_battery_optimizations
in manifest what may banned.
Comments
Post a Comment