Detect Tablet or Phone

aaronk

Well-Known Member
Licensed User
Longtime User
Hello,

I am trying to load a Layout based on if it's a Phone or a tablet.

As you know tablets have a bigger screen than a phone and I want to load a different Layout based on the screen size.

I know how to load a layout by using the following code:

B4X:
Activity.LoadLayout("Layout_Name")

I also know you can create a design script to move the objects based on percentage etc..

however what is the best way to detect what screen size the user is using, so I know what layout to show?

Is there a easy way to tell if a user is using a phone, 7" tablet or 10" tablet ?

If so, what is the best code to use to detect the screen size etc.
 

NJDude

Expert
Licensed User
Longtime User
I also know you can create a design script to move the objects based on percentage etc..

however what is the best way to detect what screen size the user is using, so I know what layout to show?

If you are using the designer scripts there's no need to detect if the device is a tablet or a phone, the script will automatically adjust the layout to the size of the screen, however, you can design a layout for portrait and another for landscape, in case you app supports both orientations.

Is there a easy way to tell if a user is using a phone, 7" tablet or 10" tablet ?

Yes, look at THIS code.
 
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
Hello,

Thanks for pointing me to the post which helps heaps..

I am now using the following code, but is there a way to detect if it's a 7" or 10" tablet ?

B4X:
If GetDevicePhysicalSize > 6 Then
   '7'' or 10'' tablet
Else
   'phone
End If
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
Just change the query:
B4X:
If GetDevicePhysicalSize = 7 Then '7 inch tab

...

If GetDevicePhysicalSize = 10 Then '10 inch tab

You can play with those results since you might not get exactly 7 or 10.
 
Last edited:
Upvote 0
Top