免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1799 | 回复: 0

[Android] 判断用户使用的是 Android 手机还是平板 [复制链接]

论坛徽章:
1
操作系统版块每日发帖之星
日期:2015-06-05 22:20:00
发表于 2015-06-04 10:45 |显示全部楼层
平时我们可以看到QQ上显示用户用的是手机还是平板,那么如何实现呢?
[Java]代码
  1. private boolean isTabletDevice() {
  2.     if (android.os.Build.VERSION.SDK_INT >= 11) { // honeycomb
  3.         // test screen size, use reflection because isLayoutSizeAtLeast is only available since 11
  4.         Configuration con = getResources().getConfiguration();
  5.         try {
  6.             Method mIsLayoutSizeAtLeast = con.getClass().getMethod("isLayoutSizeAtLeast", int.class);
  7.             Boolean r = (Boolean) mIsLayoutSizeAtLeast.invoke(con, 0x00000004); // Configuration.SCREENLAYOUT_SIZE_XLARGE
  8.             return r;
  9.         } catch (Exception x) {
  10.             x.printStackTrace();
  11.             return false;
  12.         }
  13.     }
  14.     return false;
  15. }
复制代码
如果有帮助那么看看,如果没帮助或没用,勿喷。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP