B4J Question [ABMaterial] Device recognition

MichalK73

Well-Known Member
Licensed User
Longtime User
Hello.

ABMaterial recognizes your device on your phone, tablet or PC.
However, depending on the recognized device, I would like to make some code change. How to do it ?


B4X:
If phone then
// code for phone
End if

If tablet then
// code for tablet
End if

If PC then
// code for PC
End If
 

alwaysbusy

Expert
Licensed User
Longtime User
You can use the ABMPlaform object to get some info:

usage: in WebSocket_Connected, AFTER the page.SetWebsocket(ws), put:

B4X:
Dim info As ABMPlatform = page.GetPlatform

The result is something like this:

Manufacturer:
Layout :
Name : Chrome
Version: 47.0.2526.106
OSArchitecture: 64
OSFamily: Windows
OSVersion: 10
Prerelease:
Product:
Description: Chrome 47.0.2526.106 32-bit on Windows 10 64-bit
User Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36

Maybe this together with the GetBrowserWidthHeight() this will give you a clue.
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
Hello.

ABMaterial recognizes your device on your phone, tablet or PC.
However, depending on the recognized device, I would like to make some code change. How to do it ?


B4X:
If phone then
// code for phone
End if

If tablet then
// code for tablet
End if

If PC then
// code for PC
End If

If small screen - use a small floating button... otherwise - use a regular flat button

B4X:
  Dim scwdt As Int = ABMShared.GetDeviceWidth(page)   
        Dim btncom As ABMButton
        If scwdt > -1 And scwdt < 601 Then
           btncom.InitializeFloating(page, "cm"&cnum, "mdi-action-note-add", "amber1")
        Else  
           btncom.InitializeFlat(page, "cm"&cnum,  "mdi-action-note-add", ABM.ICONALIGN_LEFT ,"Comment", "amber1")
        End If

Using GetBrowserWidthHeight (put in ABMShared...)

B4X:
Public Sub GetDeviceWidth( page As ABMPage ) As Int
   
    Dim NowWH  As String = ABM.GetBrowserWidthHeight(page)
   
    If NowWH <> "" And NowWH <> ";" Then ' check if we got something useful back
        Dim split() As String = Regex.Split(";", NowWH) ' split the string
        Dim NewH As Int = split(0)
    Else
        Dim NewH As Int = -1
    End If
   
    Return NewH
   
End Sub
 
Upvote 0
Top