Android Question Label1.TextSize = Lable1.TextSize reduces the font size on One UI v7.0

simonwilliamson

Member
Licensed User
Hi All,

I was wondering if there was a way to detect the device's software version and what the system fontsize is set to so that when I change the font size I can compensate for this known One UI 7 issue.

I know Label1.TextSize = Lable1.TextSize is non-sensical but it was the easiest way to describe the issue.
 

zed

Well-Known Member
Licensed User
Here's a small B4A class you can integrate into your project to detect:
Android version
Manufacturer and model
System font scale
One UI version (if available on Samsung devices)

Class - systeminfo.bas:
Sub GetAndroidVersion As String
    Dim jo As JavaObject
    jo.InitializeStatic("android.os.Build$VERSION")
    Return jo.GetField("RELEASE")
End Sub

' Manufacturer, model, device
Sub GetDeviceInfo As String
    Dim manufacturer As String = GetBuildField("MANUFACTURER")
    Dim model As String = GetBuildField("MODEL")
    Dim device As String = GetBuildField("DEVICE")
    Return "Manufacturer: " & manufacturer & CRLF & "Model: " & model & CRLF & "Device: " & device
End Sub

Private Sub GetBuildField(fieldName As String) As String
    Dim jo As JavaObject
    jo.InitializeStatic("android.os.Build")
    Return jo.GetField(fieldName)
End Sub

' System font size
Sub GetFontScale As Float
    Dim ctxt As JavaObject
    ctxt.InitializeContext
    Dim res As JavaObject = ctxt.RunMethod("getResources", Null)
    Dim config As JavaObject = res.RunMethod("getConfiguration", Null)

    Dim fontScale As Float = config.GetField("fontScale")
    Log("System font scale: " & fontScale)
    Return config.GetField("fontScale")
End Sub

' One UI version (Samsung only)
Sub GetSamsungOneUIVersion As String
    Dim jo As JavaObject
    jo.InitializeStatic("android.os.SystemProperties")
    Dim version As String = jo.RunMethod("get", Array("ro.build.version.sem"))
    If version.Length > 0 Then
        Return "One UI Version: " & version
    Else
        Return "One UI Version: Not detected"
    End If
End Sub

Usage:

MainPage:
Private Sub Button1_Click
    Log("Android version: " & sysinfo.GetAndroidVersion)
    Log(sysinfo.GetDeviceInfo)
    Log("System font scale: " & sysinfo.GetFontScale)
    Log(sysinfo.GetSamsungOneUIVersion)
End Sub
 

Attachments

  • log.png
    log.png
    3.5 KB · Views: 34
Upvote 1
Top