How do I know if the application works on a tablet or mobile device in Android?

I am developing an Android application that is compatible for a mobile screen and tablet screen.

So, I create 4 different screens for each. it

  • login_portrait.xml
  • login_landscape.xml
  • login_portrait_large.xml
  • login_landscape.xml

But the problem is, how to find that my application used by any user is using a tablet or mobile phone?

Is there any solution?

+4
source share
6 answers

Go For this link:

Android Developer

<resources>
    <bool name="isTablet">true</bool>
</resources>

Since the sw600dp qualifier is valid only for platforms above android 3.2. If you want to make sure that this method works on all platforms (up to 3.2), create the same file in the res / values-xlarge folder:

<resources>
    <bool name="isTablet">true</bool>
</resources>

"" ( res/values ​​/) boolean false:

<resources>
    <bool name="isTablet">false</bool>
</resources>

, :

boolean tabletSize = getResources().getBoolean(R.bool.isTablet);
if (tabletSize) {
    // do something
} else {
    // do something else
}

, . , . .

+4

:

public static boolean isTablet(Context mContext){
    return (mContext.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE;
}

, false, .

: - Android- Android?

+2

. .xml res, .

res/layout-small/login.xml             // login layout for small portrait
res/layout-normal/login.xml             // login layout for normal portrait
res/layout-normal-land/login.xml       // login layout for normal land
res/layout-large/login.xml        // login layout for large portrait
res/layout-large-land/login.xml    // login layout for large land

login.xml, .

. Android 3.2 . .

EDIT:  BTW, :

  • xlarge 960dp x 720dp
  • 640dp x 480dp
  • 470dp x 320dp
  • 426dp x 320dp

-, this .

+2

XML (bools.xml)

  • values-large
  • values-xlarge
  • values-normal
  • values-small

values-large/bools.xml values-xlarge/bools.xml

<bool name="tablet">true</bool>

values-normal/bools.xml values-small/bools.xml

<bool name="tablet">false</bool>

,

boolean isTablet = context.getResources().getBoolean(R.bool.tablet);
+2

, .

, ? , Javascript

, "user-agent".

, , twitter-bootstrap: twitter-bootstrap

+1
public static boolean isTablet(Context context) {
    return (context.getResources().getConfiguration().screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK)
            >= Configuration.SCREENLAYOUT_SIZE_LARGE;
}

Base class , , class.

0

Source: https://habr.com/ru/post/1526104/


All Articles