Development of a universal Android application (phone and tablet)

I am developing a universal application for Android, and I need to check if the application works on a tablet or phone. Is there any way to do this?

+2
source share
4 answers

You can check the Google I / O App for Android src code:

In the UIUtils class, you have the following methods:

public static boolean isHoneycomb() { // Can use static final constants like HONEYCOMB, declared in later versions // of the OS since they are inlined at compile time. This is guaranteed behavior. return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB; } public static boolean isTablet(Context context) { return (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE; } public static boolean isHoneycombTablet(Context context) { return isHoneycomb() && isTablet(context); } 
+5
source

In sdk you can create a device with the necessary attributes (screen resolution, player, touch screen, gps ...)

0
source

This is a really interesting question. I do not have an absolute answer, but you can find a good input here How to detect system information such as os or device type

Also, TelephonyManager.getPhoneType () and other methods in TelephonyManager may be of interest.

Use Context.getSystemService (Context.TELEPHONY_SERVICE) to get an instance of TelephonyManager.

0
source

New implementation from Google Jelly Bean:

  // SystemUI (status bar) layout policy int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / DisplayMetrics.DENSITY_DEVICE; if (shortSizeDp < 600) { // 0-599dp: "phone" UI with a separate status & navigation bar mHasSystemNavBar = false; mNavigationBarCanMove = true; } else if (shortSizeDp < 720) { // 600-719dp: "phone" UI with modifications for larger screens mHasSystemNavBar = false; mNavigationBarCanMove = false; } else { // 720dp: "tablet" UI with a single combined status & navigation bar mHasSystemNavBar = true; mNavigationBarCanMove = false; } } 
0
source

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


All Articles