确定该设备具有触摸屏或不 [英] Determine if the device has touch screen or not

查看:151
本文介绍了确定该设备具有触摸屏或不的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序在标准的手机上运行,​​但它也运行在我通过HDMI连接到我的电视和一个鼠标导航Android的球员。有没有一种方法以编程deterrmine设备是否具有触摸屏的支持,所以我可以导航两种方式区别?

我试过<一个href=\"http://developer.android.com/reference/android/content/pm/PackageManager.html#hasSystemFeature%28java.lang.String%29\">this,但它在两台设备上返回true:

  getPackageManager()hasSystemFeature(android.hardware.touchscreen);


解决方案

软件包管理系统将参照Android的播放器本身,这可能有一个触摸屏。如果玩家显示器被通过HDMI传送到外部监视器无法检测。当你问包管理器如果设备有触摸屏,它指的是球员,而不是外部显示器。

有一件事情你可以做的是,如果HDMI端口处于激活状态检测,如果播放器连接到外部显示器通过检查,并相应地改变你的导航。

请参阅:检测HDMI端口在Android设备

边注:如果玩家没有触摸屏,但包管理器错误地报告它的话,那么它的无论是用包管理器或缺陷的设备制造商实施的Andr​​oid可能是越野车

My app runs on standard phones but it also runs on Android players which I connect via HDMI to my TV and work with a mouse to navigate. Is there a way to programatically deterrmine whether the device has touch screen support so I can distinguish between the two ways of navigation?

I tried this, but it returns true on both devices:

getPackageManager().hasSystemFeature("android.hardware.touchscreen");

解决方案

PackageManager will refer to the Android player itself which probably has a touchscreen. It cannot detect if the player display is being routed to an external monitor via HDMI. When you ask the package manager if the device has a touchscreen, it is referring to the player and not the external display.

One thing you could do is to detect if the player is connected to an external display by checking if HDMI port is active and change your navigation accordingly.

See: Detect HDMI Port in android device

Side note: If the player does not have a touchscreen but the package manager is wrongly reporting that it does, then it's either a bug with package manager or the device manufacturers implementation of Android might be buggy.

这篇关于确定该设备具有触摸屏或不的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆