Dim p As Phone
If p.SdkVersion >= 23 Then
Dim JavaObjectOpt As JavaObject
JavaObjectOpt.InitializeContext
Dim batteryIgnore As Boolean = JavaObjectOpt.RunMethod("isIgnoringBatteryOptimizations", Null)
Log ("Battery optimization ignored: " & batteryIgnore) ' should be TRUE if app is excluded from optimization
If batteryIgnore = False Then
Dim msgOptiBatt As Object = Msgbox2Async("Do you want to exclude app from battery optimization?", "Battery optimization", "Yes", "", "No", Null, False)
Wait For (msgOptiBatt) Msgbox_Result (Result As Int)
If Result = DialogResponse.POSITIVE Then
'if YES, after starting intent you need to select all application in drop down, then you need to find your application and turn on or tick box after application name.
Dim StartIntentBatt As Intent
StartIntentBatt.Initialize("android.settings.IGNORE_BATTERY_OPTIMIZATION_SETTINGS", "")
StartActivity(StartIntentBatt)
End If
Else
MsgboxAsync("App is already excluded from battery optimization"))
End If
End If