如何确定 Android 设备是否有触摸屏?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3454650/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to determine if an Android device has a touchscreen?
提问by Hidden Android
I'm spending considerable time in making my UI to work with keyboard input only. But in the end I'm not sure whether I can rely on the assumption that Android devices all have touch screens.
我花了大量时间让我的 UI 只使用键盘输入。但最终我不确定我是否可以依赖 Android 设备都具有触摸屏的假设。
Is there a way to determine if an Android device has a touch screen?
有没有办法确定 Android 设备是否有触摸屏?
采纳答案by Neil Traft
You should research the existing devices and read the Android Compatibility Definition Document(CDD) and decide for yourself.
您应该研究现有设备并阅读Android 兼容性定义文档(CDD) 并自行决定。
I have spent some considerable time trying to figure out this problem for myself. The posters above are correct that Android already powers some non-touch devices and will power Google TV in the near future, but as it currently stands, the CDD specifically requires that ALL Android devices MUST have a touchscreen.
我花了相当多的时间试图为自己解决这个问题。上面的海报是正确的,Android 已经为一些非触摸设备提供动力,并将在不久的将来为Google TV 提供动力,但就目前而言,CDD 特别要求所有 Android 设备必须有触摸屏。
Basically, the Android Compatibility program was created to hedge against the sort of fragmentationissues you're worrying about now. It lists a bunch of requirements, and if a device does not meet those requirements, it does not get access to Android Market. These requirements include a touchscreen, wireless communication, bluetooth, a camera, and much more.
基本上,创建 Android 兼容性计划是为了避免您现在担心的那种碎片化问题。它列出了一系列要求,如果设备不满足这些要求,则无法访问 Android Market。这些要求包括触摸屏、无线通信、蓝牙、摄像头等等。
If you research those tablets and netbooks, you will find that not a single onecarries the Android Market. Augen recently tried to pull a fast one with their new GENTOUCH 78 tablet, but had to rescind their claimsthat the tablet would carry Android Market after being shot down by the Android Compatibility Team.
如果你研究那些平板电脑和上网本,你会发现没有一个是 Android Market 的。奥根最近试图用他们的新 GENTOUCH 78 平板电脑拉一个快的,但不得不撤销他们的说法,即平板电脑在被 Android 兼容性团队击落后将搭载 Android Market。
So, if you are only distributing your app through Android Market, you have nothing to worry about until Google changes the CDD. But if you'd like to offer your app on other app stores or as a direct download, then you'll have to worry about your key mode navigation issues.
因此,如果您只是通过 Android Market 分发您的应用程序,那么在 Google 更改 CDD 之前,您无需担心。但是,如果您想在其他应用程序商店或直接下载提供您的应用程序,那么您将不得不担心您的按键模式导航问题。
If it's any consolation, I have found that many, manyapps have the exact same problem; they are impossible to use without a touchscreen. Many of them also have serious issues with focus and the soft keyboard. Sometimes the keyboard stays up when it should be hidden. Sometimes you can't get the keyboard to pop up no matter how many times you click on an EditText. IMO, the Android framework does not handle these things all that well.
如果有什么安慰的话,我发现很多很多应用程序都有完全相同的问题;如果没有触摸屏,它们就无法使用。他们中的许多人在焦点和软键盘方面也存在严重问题。有时键盘在应该隐藏时会保持打开状态。有时,无论您单击 EditText 多少次,都无法让键盘弹出。IMO,Android 框架不能很好地处理这些事情。
Given all that, it will certainly be interesting to see how Google TV fits into all this. Will they update the CDD to be compatible with their set-top boxes? Will they use a different SDK and CDD for Google TV implementations? Will they ignore the Compatibility Program altogether when it comes to Google TV? Your guess is as good as mine.
鉴于所有这些,看看 Google TV 如何适应这一切肯定会很有趣。他们会更新 CDD 以与他们的机顶盒兼容吗?他们是否会为 Google TV 实施使用不同的 SDK 和 CDD?当涉及到 Google TV 时,他们会完全忽略兼容性计划吗?你的猜测和我的一样好。
Update:
It seems that someone at Google has finally come forward and admitted that Android is not ready to run on a tablet:
http://phandroid.com/2010/09/10/shocker-google-says-android-not-meant-for-tablets-in-its-current-state/
更新:
似乎谷歌的某个人终于站出来承认 Android 还没有准备好在平板电脑上运行:http:
//phandroid.com/2010/09/10/shocker-google-says-android-not-meant -for-tablets-in-its-current-state/
To me, this says that Google was not prepared for the accelerated adoption of the Android OS and has not adequately roadmapped the future of the platform. Supporting screens larger than 480x800 is barely possible, and Samsung was only able to do it by working closely with Google on the Galaxy Tab. So I'm not so sure we need to worry about non-touchscreen devices in the near future. They'll be here eventually, I'm sure, but when they do arrive we may see a separate app market just for those, or some altered filtering scheme on the existing market, a new CDD, who knows.
对我来说,这表明谷歌没有为加速采用 Android 操作系统做好准备,也没有充分规划该平台的未来。支持大于 480x800 的屏幕几乎是不可能的,三星只能通过在 Galaxy Tab 上与谷歌密切合作才能做到这一点。所以我不太确定我们是否需要在不久的将来担心非触摸屏设备。他们最终会在这里,我敢肯定,但是当他们到达时,我们可能会看到一个单独的应用程序市场,或者现有市场上的一些改变的过滤方案,一个新的 CDD,谁知道呢。
To me, this says that Google is still playing it by ear, and we'll just have to do the same.
对我来说,这说明 Google 仍在听从它,而我们也只能这样做。
回答by Moncader
All the phones so far have touch screens, but there is no promise that they must.
到目前为止,所有的手机都有触摸屏,但没有保证必须这样做。
However there are lots of netbooks, notebooks, and soon to be TVs that have no touch screen. However these devices have mice. From what I've seen, the mouse input gets pumped through the touch system so MouseDown is ACTION_DOWN, etc... (Don't know about right click though)
然而,有很多上网本、笔记本电脑,以及很快就会出现没有触摸屏的电视。然而,这些设备有鼠标。从我所看到的,鼠标输入通过触摸系统被泵送,所以 MouseDown 是 ACTION_DOWN 等......(虽然不知道右键单击)
回答by Dylan
Are you targetting just the phones? Android is appearing on many devices including TV'sI've no idea if new libs will be released to isolate parts of the devices from each other, but if you want a broader audience I'd suggest keeping the keyboard input available if you are
你只针对手机吗?Android 出现在包括电视在内的许多设备上我不知道是否会发布新库以将设备的各个部分相互隔离,但如果您想要更广泛的受众,我建议您保持键盘输入可用
回答by larham1
Google TV (GTV) is the most popular Android notouch device (as of the time this answer is composed). However, there are several devices that will call for notouch renderings if you have "notouch" resources (e.g. a directory like res/layout-notouch/ )
Google TV (GTV) 是最受欢迎的 Android 触控设备(截至撰写此答案时)。但是,如果您有“notouch”资源(例如 res/layout-notouch/ 之类的目录),则有几种设备会调用 notouch 渲染
To accommodate notouch devices, made sure that focus will cause a visual selection indicator, and (for GTV) that keystroke listeners are in place for the directional-pad center button. Using default widgets and themes will often accomplish much of this automatically. If you make your own buttons, you need background 9-patches for focused and focused+pressed.
为了适应触摸设备,确保焦点将导致视觉选择指示器,并且(对于 GTV)按键监听器位于方向板中心按钮的位置。使用默认小部件和主题通常会自动完成大部分工作。如果您制作自己的按钮,则需要背景 9 补丁用于聚焦和聚焦 + 按下。
Running on a GTV is a good test environment to make sure that notouch works well, and GTV has an emulatornow, though it runs only on Linux/x86.
在 GTV 上运行是一个很好的测试环境,可以确保 notouch 运行良好,而且GTV现在有一个模拟器,尽管它只能在 Linux/x86 上运行。