Dim ref As Reflector
ref.Target = ref.GetActivity
ref.Target = ref.RunMethod("getWindow")
ref.Target = ref.RunMethod("getAttributes")
Dim brightness As Float = ref.GetField("screenBrightness")
I get brightness = -1
how can I get the real value?
However if the screen brightness is set to automatic then the first value will be -1. You can explicitly set the brightness to 0.7 when your app starts.
Sub SetBrightnessToNormalMode
Dim jo As JavaObject
jo.InitializeContext
Dim System As JavaObject
System.InitializeStatic("android.provider.Settings.System")
System.RunMethod("putInt", Array( _
jo.RunMethod("getContentResolver", Null), _
System.GetField("SCREEN_BRIGHTNESS_MODE"), _
System.GetField("SCREEN_BRIGHTNESS_MODE_MANUAL")))
End Sub
For some reason rp.CheckAndRequest("android.permission.WRITE_SETTINGS") did not open the permission dialogue on my device
so i get this exception
Error occurred on line: 67 (Main)
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:131)
at b4a.example.brightness.main._setbrightnessmode(main.java:452)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA$2.run(BA.java:370)
at anywheresoftware.b4a.BA.setActivityPaused(BA.java:442)
at b4a.example.brightness.main$ResumeMessage.run(main.java:306)
at android.os.Handler.handleCallback(Handler.java:836)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:203)
at android.app.ActivityThread.main(ActivityThread.java:6251)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
Caused by: java.lang.SecurityException: b4a.example.brightness was not granted this permission: android.permission.WRITE_SETTINGS.
at android.os.Parcel.readException(Parcel.java:1683)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:188)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:140)
at android.content.ContentProviderProxy.call(ContentProviderNative.java:646)
at android.provider.Settings$NameValueCache.putStringForUser(Settings.java:1578)
at android.provider.Settings$System.putStringForUser(Settings.java:1958)
at android.provider.Settings$System.putIntForUser(Settings.java:2063)
at android.provider.Settings$System.putInt(Settings.java:2057)
... 19 more
** Activity (main) Resume **
i also noticed.
i think because every user will agree all permissions (or u can not use most of all apps^^)
google hide this settings. but u can open the os permissions dialog via intent where the user can enable it manual.
in the runtime permissions erel made and in the firs test i made for it few weeks ago it did opend.
but since then they dont show.
this is probably why the BrightnessTest.zip you posted befor don't work for me because the permission is false
but why they do not open?
do you have any benefit from the sensor data itself?
it is possible to read this sensor in app game kit with GetRawLightLevel so it should also possible in b4a.
If an ambient light sensor exists, get the measurement of the surrounding light in lumels as a float.
Thanks friends
With the help of your help, I succeeded in solving the issue.
The dialogue has not yet opened to me, but I think it's a subject for new thread.