Android Code Snippet Lock Screen Rotation

A friend of mine asked me if there was a way to temporary stop screen rotation and then restore it.

I didn't get into why they needed to do so, but gave them this code I had

B4X:
Public  Sub LockUnLock_ScreenOrientation(xLock As Boolean)
             Dim j As JavaObject
    
             j.InitializeContext
             j.RunMethod("jLockUnLock_ScreenOrientation",Array(xLock))
End Sub

#If JAVA
 import android.content.pm.ActivityInfo;
 
 public void jLockUnLock_ScreenOrientation(Boolean xlock)
 {
     if  (xlock) {
        BA.Log("**** Lock Orientation");             
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
    }
    else {
        BA.Log("**** UnLock Orientation");                 
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);    
    }
 }
#End If

B4X:
            LockUnLock_ScreenOrientation(True)   ' Lock screen rotation
            LockUnLock_ScreenOrientation(False)  ' Restore rotation and use sensor to determine which way

Seems to work just fine.

Not sure if this helps anyone.

BobVal
 

Wosl

Member
Unless this is an old thread - Thank you, Bob

This is a possible solution to calm hectic users when they switch the screen orientation permanently.

Wosl

PS:
Dear Bob,

It's surprising and wonderful to meet someone who helped shape the computer age and is still active today. That's how I feel now, having learned on an IBM mainframe in the 1970s and continuing to learn new computer languages and hardware to this day.

Keep up the good work!
Greetings from Germany
 
Top