Determine if the device is a smartphone or tablet?
This subject is discussed in the Android Training:
Use the Smallest-width Qualifier
If you read the entire topic, they explain how to set a boolean value in a specific value file (as res/values-sw600dp/attrs.xml):
<resources>
<bool name="isTablet">true</bool>
</resources>
Because the sw600dp qualifier is only valid for platforms above android 3.2. If you want to make sure this technique works on all platforms (before 3.2), create the same file in res/values-xlarge folder:
<resources>
<bool name="isTablet">true</bool>
</resources>
Then, in the "standard" value file (as res/values/attrs.xml), you set the boolean to false:
<resources>
<bool name="isTablet">false</bool>
</resources>
Then in you activity, you can get this value and check if you are running in a tablet size device:
boolean tabletSize = getResources().getBoolean(R.bool.isTablet);
if (tabletSize) {
// do something
} else {
// do something else
}
How to detect device is Android phone or Android tablet?
You can also try this
Add boolean parameter in resource file.
in res/values/dimen.xml file add this line
<bool name="isTab">false</bool>
while in res/values-sw600dp/dimen.xml file add this line:
<bool name="isTab">true</bool>
then in your java file get this value:
if(getResources().getBoolean(R.bool.isTab)) {
System.out.println("tablet");
} else {
System.out.println("mobile");
}
How to find Tablet or Phone in Android , Programmatically?
Try this
public boolean isTablet(Context context) {
boolean xlarge = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == 4);
boolean large = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE);
return (xlarge || large);
}
It will return true if you are using a tablet. It has been checked on Samsung Galaxy Tab 7" and Samsung Galaxy S3.
Detect if device is tablet
If you want to just use vanilla javascript you can use the navigator API
const userAgent = navigator.userAgent.toLowerCase();
const isTablet = /(ipad|tablet|(android(?!.*mobile))|(windows(?!.*phone)(.*touch))|kindle|playbook|silk|(puffin(?!.*(IP|AP|WP))))/.test(userAgent);
console.log(isTablet)
Detecting whether Android device is a phone or a tablet with javascript
You should probably use this sugestion made by google by reading the user agent. If the UA has the word mobile it's a phone, if it doesn't it's a tablet
http://googlewebmastercentral.blogspot.com/2011/03/mo-better-to-also-detect-mobile-user.html
Related Topics
Actionbarsherlock + Tabs + Multi Fragments
Ontaskremoved() Not Getting Called in Huawei and Xiaomi Devices
Linkedlist Put into Intent Extra Gets Recast to Arraylist When Retrieving in Next Activity
Complete Working Sample of the Gmail Three-Fragment Animation Scenario
How to Make a Phone Call Programmatically
Opening Android Settings Programmatically
How to Build Signed APK from Android Studio for Flutter
How to Style the Drawerarrowtoggle from Android Appcompat V7 21 Library
Can't Run a Java Android Program with Valgrind
How to Package Native Commandline Application in APK
Get Ssid When Wifi Is Connected
Android:Static Fields and Memory Leaks
Proguard Causing Runtimeexception (Unmarshalling Unknown Type Code) in Parcelable Class
How to Verify That an Android APK Is Signed with a Release Certificate
Android Studio: How to Attach Android Sdk Sources