NullPointerException at anywheresoftware.b4a.phone.Phone.SetScreenBrightne ss

NeoTechni

Well-Known Member
Licensed User
Longtime User
I'm trying to use it to turn off the screen when the proximity sensor reads something is close to it/turn it back on when the proximity sensor no longer reads the object.

I'm using

B4X:
Sub SetScreenBrightness(Value As Float)
   Dim phone1 As Phone
   phone1.SetScreenBrightness(Value)
End Sub

Inside a code module, cause when I try the same code within an activity module it won't let me use SetScreenBrightness, just Initialize, InitializeWithPhoneState and StopListening. And it won't work inside a service module as per the documentation.

When an object is close the proximity sensor reads 0 so I use SetScreenBrightness(0) and when an object isn't close it reads mysensor.MaxValue so I use SetScreenBrightness(-1) which should be automatic brightness

And I get:

java.lang.NullPointerException
at anywheresoftware.b4a.phone.Phone.SetScreenBrightness(Phone.java:183)

Caused by: java.lang.NullPointerException
at anywheresoftware.b4a.phone.Phone.SetScreenBrightness(Phone.java:183)
 

madSac

Active Member
Licensed User
Longtime User
Check the attached project.I have tested it and it is working properly with no error.
 

Attachments

  • demo.zip
    5.7 KB · Views: 156
Upvote 0

NeoTechni

Well-Known Member
Licensed User
Longtime User
The problem was the phone variable was used elsewhere in the program but Android's concept of scope is not what I'm used to. Renaming the variable fixed it.

But Erel, I would like to email you my APKs so you can see what I've done with your IDE.
 
Upvote 0
Top