作者weruioi (傑)
看板AndroidDev
標題Re: [問題] 在ICS上區分phone or tablet ?
時間Wed Feb 15 23:45:20 2012
※ 引述《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)
1F:→ ipure:這怎麼好像也是看版本來區分的 @_@ ? 02/17 09:32
2F:→ PeterLiu:原Po開頭就有寫了: 版本 跟 螢幕尺寸...XDD 02/17 09:53
3F:→ Eior:我一直很想確認一件事,確定靠 尺寸+dp 不能判斷嗎? 02/17 10:27
5F:→ PeterLiu:感謝樓上的分享,我好好研究一下... 02/17 13:02