androiddevice-detection

How to detect device is Android phone or Android tablet?


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?

Edit:

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.


Solution

  • 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");
    }