I have two apps for Android tablets and Android phones. For tablet app I set android:minSdkVersion="11"
. But nowadays Android phones like Galaxy S3 has Android version 4.0.4 so S3 users can download my tablet app from Google Play Store. I want to warn phone users to download phone app when they install tablet app. Vice versa for tablet users download tablet app when they run phone app.
Is there any easy way to detect the device type?
I found solution on this link.
In your manifest file you can declare screen feature for handset and tablets then Google Play decides download permissions for both phone and tablet.
On your device, go to the Home screen (the one with all the icons), and tap on the Settings icon. Scroll down and tap on About phone or About tablet. Some information will appear. If one of the lines of information says Android with a version number, you have an Android device.
Open 'Settings' and then 'About tablet' on the bottom left side. Then you will find 'Device name' (e.g. “Galaxy Tab A (2016)”) and 'Model number' (e.g. “SM-T585”) below. After choosing 'Software information', you'll see the 'Android version' (e.g. “7.0”).
An Android tablet is a tablet-sized PC that runs on Google's Android operating system (OS). Android tablets include almost all the key features found in a regular tablet PC, including office applications, games, Web browsers and many other programs.
Use this:
public static boolean isTablet(Context context) { return (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE; }
which will return true if the device is operating on a large screen.
Some other helpful methods can be found here.
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"); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With