I would like to run this code from my Service module to dim the display. It works fine in my Main activity but the p.SetScreenBrightness(14/255) chokes in the Service module. I'm trying to dim the whole phone display, not just while my app is running. I can do this from an activity just fine but the Service module doesn't seem to like it. Is there any way around this? Thanks...
B4X:
Dim p As Phone
WriteSetting("screen_brightness", 14)
p.SetScreenBrightness(14/255)
Sub WriteSetting(Setting As String, Value As Int)
Dim r1 As Reflector
Dim args(3) As Object
Dim types(3) As String
r1.Target = r1.GetContext
args(0) = r1.RunMethod("getContentResolver")
types(0) = "android.content.ContentResolver"
args(1) = Setting
types(1) = "java.lang.String"
args(2) = Value
types(2) = "java.lang.int"
r1.RunStaticMethod("android.provider.Settings$System", "putInt", args, types)
End Sub