作者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