2011-07-29 173 views

回答

5

您可以檢查Google I/O App for Android SRC代碼:

UIUtils班級你有以下方法:

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); 
} 
+0

它工作正常。謝謝! – Alex

+0

你好Macarse,我有一個問題涉及到這個話題...我如何開發將在手機(2.2及更高版本)和平板電腦上運行的通用應用程序? –

+0

開發應用程序時使用兼容包。你可以在這裏閱讀更多[http://developer.android.com/sdk/compatibility-library.html] – Sandra

0

在SDK中,您可以創建你想要的atributes設備(屏幕分辨率,內存,觸摸屏,GPS ....)

0

這實際上是一個有趣的問題。 我沒有一個絕對的答案,但你可能在這裏找到一些不錯的輸入How to detect system information like os or device type

而且也TelephonyManager.getPhoneType()和TelephonyManager其他方法可能會感興趣。

使用Context.getSystemService(Context.TELEPHONY_SERVICE)獲取TelephonyManager的一個實例。

+0

馬沙爾的答案看起來也很有希望。 – Petrus

0

從谷歌果凍豆新的實現:

// 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

什麼是shortSize? –

相關問題