Re: [問題] 在ICS上區分phone or tablet ?

看板AndroidDev作者 (傑)時間12年前 (2012/02/15 23:45), 編輯推噓0(005)
留言5則, 3人參與, 最新討論串2/3 (看更多)
※ 引述《PeterLiu (阿勇)》之銘言: : 在舊版的android上,可以簡單利用系統版本來區分device : ver 2.x 是手機,ver 3.x 是平板 : (至少八九不離十) : 現在 4.x 則是手機平板通用, : 當app上某個功能我希望只能在平板上才開放時, : 請問要如何去區別app是裝在手機or平板? : 本來想說利用解析度去判別,但是現在手機也是有 1280x720...=.= 節錄自GoogleIO 2011 app source code 兩個判斷版本與螢幕大小的function 希望有幫助XD 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 isHoneycombTablet(Context context) { // 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 isHoneycomb() && (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.32.239.249 ※ 編輯: weruioi 來自: 114.32.239.249 (02/15 23:46)

02/17 09:32, , 1F
這怎麼好像也是看版本來區分的 @_@ ?
02/17 09:32, 1F

02/17 09:53, , 2F
原Po開頭就有寫了: 版本 跟 螢幕尺寸...XDD
02/17 09:53, 2F

02/17 10:27, , 3F
我一直很想確認一件事,確定靠 尺寸+dp 不能判斷嗎?
02/17 10:27, 3F

02/17 10:44, , 4F
google groups: http://ppt.cc/7CHV
02/17 10:44, 4F

02/17 13:02, , 5F
感謝樓上的分享,我好好研究一下...
02/17 13:02, 5F
文章代碼(AID): #1FEzCJRr (AndroidDev)
討論串 (同標題文章)
文章代碼(AID): #1FEzCJRr (AndroidDev)