Android Question Excluding landscape orientated devices in manifest (physical home button is on longest edge)

PhilN

Member
Licensed User
Longtime User
I have installed my compass app which runs only in portrait mode on a landscape orientated tablet (the physical home button is on the longest edge) for testing. The layout is fine since the app is forced to run in portrait mode but the heading is out by 90 degrees. This means that the magnetic sensors are rotated by 90 degrees when compared to a vertically oriented tablet or phone (physical home button is on the shortest edge). In the code below, thanks to Erel, I am able to determine a device's default orientation at runtime. I am in the process of listing my app on Google Play and I would prefer to exclude devices whose default orientation is landscape in the manifest. I have looked at the Android manifest code that could possibly exclude such devices but I am not certain how to exclude them. How do I exclude the horizontally orientated devices (physical home button is on longest edge) from installing my app on Google Play in the manifest?

B4X:
'True = Landscape, False = Portrait
Sub GetDefaultOrientation As Boolean
   Dim context As JavaObject
   context = context.InitializeStatic("anywheresoftware.b4a.BA").GetField("applicationContext")
   Dim rotation As Int = context.RunMethodJO("getSystemService", Array As Object("window")) _
     .RunMethodJO("getDefaultDisplay", Null).RunMethod("getRotation", Null)
   Dim configOrientation As Int = context.RunMethodJO("getResources", Null).RunMethodJO("getConfiguration", Null) _
     .GetField("orientation")
   If ((rotation = 0 OR rotation = 2) AND configOrientation = 2) OR _
     ((rotation = 1 OR rotation = 3) AND configOrientation = 1) Then
     Return True
   Else
     Return False
   End If
End Sub
 

MarcoRome

Expert
Licensed User
Longtime User
Read for more information:


1594486210885.png
 
Upvote 0

PhilN

Member
Licensed User
Longtime User
Thank you Marco. I will use the <uses-feature android:name="android.hardware.screen.portrait"/> in my manifest.
 
Upvote 0
Top