Howto use Reflection library to access Display.getRotation()

joseluis

Active Member
Licensed User
Longtime User
I just requested for a library to access the Display class, in order to access the getRotation() method, but it seems that the Reflection library is enough to get that data.

I've not wrapped my head around the Reflection library yet. And I very much desire to know what it can and cannot do, and the correct approach to do it. Hopefully this example will be enough to understand it once for all.

Could anybody share some luminous expertise into this subject?
 

joseluis

Active Member
Licensed User
Longtime User
Ok, my first try:

B4X:
Dim r As Reflector
Dim rotation As Int
rotation = r.RunMethod2("getRotation", "", "android.view.Display")
Log(rotation)
But it gives the error: java.lang.NullPointerException

I'll try again when I arrive home
 
Upvote 0

joseluis

Active Member
Licensed User
Longtime User
Yes! I did it! This code works! :icon_clap:
B4X:
Dim r As Reflector
Dim rotation As Int
r.Target = r.GetActivity
r.Target = r.RunMethod("getWindowManager")
r.Target = r.RunMethod("getDefaultDisplay")
rotation = r.RunMethod("getRotation")
Log(rotation)
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…