Re: [問題] 在ICS上區分phone or tablet ?
※ 引述《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
02/17 09:53, 2F
→
02/17 10:27, , 3F
02/17 10:27, 3F
→
02/17 10:44, , 4F
02/17 10:44, 4F
→
02/17 13:02, , 5F
02/17 13:02, 5F
討論串 (同標題文章)