Android Question Exclude low screen aspect devices (smaller than 1.5) in manifest

PhilN

Member
Licensed User
Longtime User
My compass app has a unique 3 part layout: top, center and bottom. I have determined the lowest screen aspect to display my app properly to be 1.5 or else the 3 parts start to over lap. How can I set the min aspect ratio in the manifest to exclude installs to devices with a too low screen aspect?

According to this page one can set the maximum aspect ratio but I do not see how one can set the minimum aspect ratio.
 
Last edited:

MarcoRome

Expert
Licensed User
Longtime User

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Dim getRes As JavaObject =  GetContext.RunMethodJO("getResources", Null)
    Dim getDisplay As JavaObject = getRes.RunMethodJO("getDisplayMetrics",Null)
    Dim H As Int = getDisplay.GetField("heightPixels")
    Dim W As Int = getDisplay.GetField("widthPixels")
    Dim AspectRatio As Float = H / W
    Log(AspectRatio)
    Log(H)
    Log(W)
    If AspectRatio < 1.5 Then
        Log("Negate")
    End If
    
    'OR more simple without javaobject only B4A
    Log("*************")
    
    Dim H1 As Int = GetDeviceLayoutValues.Height
    Dim W1 As Int = GetDeviceLayoutValues.Width
    Dim AspectRatio1 As Float = H1 / W1
    Log(AspectRatio1)
    Log(H1)
    Log(W1)
    If AspectRatio1 < 1.5 Then
        Log("Negate")
    End If

End Sub

    

Sub GetContext As JavaObject
    Return GetBA.GetField("context")
End Sub

Sub GetBA As JavaObject
    Dim jo As JavaObject
    Dim cls As String = Me
    cls = cls.SubString("class ".Length)
    jo.InitializeStatic(cls)
    Return jo.GetFieldJO("processBA")
End Sub
 
Upvote 0

PhilN

Member
Licensed User
Longtime User
Thanks again Marco. What you suggested is more or less what I am doing at runtime at the moment, but it would have been better to exclude the devices in the manifest so that people would not unnecessarily install the app and then have to uninstall it anyway. According to the post you referred to On Android Q there is a new attribute "android:minAspectRatio". This might help in future releases of my app.
 
Upvote 0
Top