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
with this:
int curBrightnessValue = android.provider.Settings.System.getInt(getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS);
Thanks...I took a look at trying to rewrite it but it's beyond my understanding...I looked at the Reflection docs but really don't know which method() I would need to make it work. Franky, I don't understand the Reflection doc very well.
Since it's a simple function call, I thought the RunMethod would work but I don't know what argument is needed in that method. I'm not even sure RunMethod is the right method that needs to be used.
Here is what I have below but it doesn't work. I'm guessing at the RunMethod argument "getScreenBrightness" because I don't know what it should be. I also tried "Screen_Brightness" but that didn't work.
I can't figure out how to convert your android example into what B4A needs.
B4X:
Sub GetBrightness() As Int
Dim r As Reflector
r.Target = r.RunStaticMethod("java.util.Locale", "getDefault", Null, Null)
Return r.RunMethod("getScreenBrightness")
End Sub
It's more towards this code
but this needs a little help too
to get it working :sign0085:
B4X:
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) = "SCREEN_BRIGHTNESS"
types(1) = "java.lang.String"
args(2) = -1
types(2) = "java.lang.int"
Dim BrightInt As Int
BrightInt = r1.RunStaticMethod("android.provider.Settings$System", "getInt", args, types)
Msgbox(BrightInt,"bright")
from:
int UserBrightness = Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS,-1);
Yes I have the WRITE_SETTINGS statement in my manifest.
I guess where I get lost is I don't understand what the args() array and the types() array are doing. I understand they are array structures and that they are being passed to the RunStaticMethod() but I don't understand or know why I would use the RunStaticMethod() vs RunMethod4() for example.
I see args(0) element is loaded with r1.RunMethod() but I don't understand why.
I think what's missing from the Reflection doc is a beginners tutorial on the structure of making Reflection calls. The doc shows all the objects and methods, etc. but doesn't explain the structure options. I see several structure options (RunMethod, Method1, Method2) but don't know why I would pick one over the other.