Hi guys,
I want to ask user for ignoring Battery Optimizations. Here is my codes :
Those codes run OK if user allows it, but when user denied it, the line after Wait for in sub Activity_Resume never executed and app runs in a loop, asked user again for permission.
I wan app to terminate/quit If user denied permission.
Anyone care to give me a hint? Thanks.
Note : the code for ask battery permission, got from here :
www.b4x.com
I want to ask user for ignoring Battery Optimizations. Here is my codes :
B4X:
Sub RequestPowerMngt As ResumableSub
Private Api As Int
Private r As Reflector
Api = r.GetStaticField("android.os.Build$VERSION", "SDK_INT")
Log(Api)
If Api >= 23 Then
Dim JavaObject1 As JavaObject
JavaObject1.InitializeContext
Dim Ignoring As Boolean=JavaObject1.RunMethod("isIgnoringBatteryOptimizations", Null)
If Ignoring=False Then
Dim JavaObject1 As JavaObject
JavaObject1.InitializeContext
JavaObject1.RunMethod("ShowPermissionDialog", Null)
End If
Log(JavaObject1.RunMethod("isIgnoringBatteryOptimizations", Null))
Return JavaObject1.RunMethod("isIgnoringBatteryOptimizations", Null)
Else
Return True
End If
End Sub
Sub Activity_Resume
Wait For(RequestPowerMngt) Complete(Rsl As Boolean)
Log(1)
If Rsl = False Then
Log("No access")
End If
End Sub
Those codes run OK if user allows it, but when user denied it, the line after Wait for in sub Activity_Resume never executed and app runs in a loop, asked user again for permission.
I wan app to terminate/quit If user denied permission.
Anyone care to give me a hint? Thanks.
Note : the code for ask battery permission, got from here :
About runtime permission
Just a confirmation if I'm doing correctly: I have declared in "configure paths" the android-23 platform. This because I want to manage a runtime permission in Android 6 and force the user to exclude the App from the battery optimization Sub Activity_Resume If GetAndroidApiLevel>=23 Then...

Last edited: