B4J Question [ABMaterial][SOLVED] Determining Device type.... discrepancies

Cableguy

Expert
Licensed User
Longtime User
Hi gys...
Its me again... yeah, I know...

So.... trying to determining the device type is proving to be not as simple as using the "isPhone, isTablet, isDestop" calls...
Consider this code, that I borowed from @Harris....
B4X:
    LogError("this is a desktop : " & pg.IsDesktop)
    LogError("this is a tablet : " & pg.IsTablet)
    LogError("this is a phone : " & pg.IsPhone)
    Log("So this is a " & pg.GetCurrentPageSize)
Just a bunch of logs, but aren't they usefull!!!
In my desktop, All is GOOD!
B4X:
....
this is a desktop : true
this is a tablet : false
this is a phone : false
Waiting for value (101 ms)
So this is a desktop
....

BUT in my Samsung S20....
B4X:
....
this is a desktop : true
this is a tablet : false
this is a phone : false
Waiting for value (101 ms)
So this is a phone
....

In the first case, both isDesktop and page.getCurrentPageSize agree that this is a Desktop... or a laptop in my case, But the second case, isDesktop still returns true, isPhone returns false, but the page.getCurrentPageSize correctly determines this to be a Phone!

@alwaysbusy once stated about this that....
The IsPhone/IsTablet/IsDesktop returns the device type. No matter what the screen size is, this will stay the same as the device doesn't change.
But these finding seem to contradict this.
 

alwaysbusy

Expert
Licensed User
Longtime User
Do you run Page.CheckDevice(ws.UpgradeRequest) before the calls?

IsPhone, IsTablet and IsDesktop use the User-Agent to try to find out what device it is so that should be consistent. It basically analyses the user-agent for keywords if it is a phone or a tablet. If nothing is found, then it is a desktop. Maybe the S20 somehow fakes being another device?
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Do you run Page.CheckDevice(ws.UpgradeRequest) before the calls?

IsPhone, IsTablet and IsDesktop use the User-Agent to try to find out what device it is so that should be consistent. It basically analyses the user-agent for keywords if it is a phone or a tablet. If nothing is found, then it is a desktop. Maybe the S20 somehow fakes being another device?
Hi Alain, No I didnt do that call before the other calls... I will try that... How can I check if my phone is pretending to be a desktop?
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
B4X:
Dim device As String=ws.UpgradeRequest.GetHeader("User-Agent")
log(device)
This is what I got:
Mozilla/5.0 (Linux; Android 11; SAMSUNG SM-G980F) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/13.0 Chrome/83.0.4103.106 Mobile Safari/537.36
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
Hummm, never even knew about that call...
Isphone, Istablet work fine on all my test devices.

I have also used this in the past to determine the same....


B4X:
 Sub setScrnSize2(pg As ABMPage) as Int
'   
'    Dim ret As Int = 2
'    Try
'    Dim NowWH As String = ABM.GetBrowserWidthHeight( pg) ' returns a string "width;height"
'   
'   
'    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)
'        Log(" width in PX: "&NewH)
'       
'       
'       If NewH < 600 Then ret = 0    ' phone
'        If NewH > 600 And NewH <= 992 Then ret = 1  ' tablet landscape
'        If NewH > 992 Then ret = 2 ' desktop
'
'
'    End If
'    Catch
'        Log(" screen setting failed!")
'    End Try   
'    Log(" screen width: " &ret)
'    ScrnSize = ret
'    Return ret

End Sub
B4X:
 
Upvote 0
Top