Android:以编程方式检测设备是否有硬件菜单按钮
我目前正在努力解决这个问题。我需要检查安装应用程序的设备是否有硬件菜单键。由于它在 Galaxy Nexus 等某些设备上不存在,因此在本例中我直接在 UI 中显示它。
我已经查看过 PackageManager.hasSystemFeature(),但没有发现任何有用的东西。
有人已经这样做了吗?
I'm currently struggling with this issue. I need to check if the device, where the app is installed, has a hardware menu key. Because it is not existing on some devices like Galaxy Nexus, I'm showing it directly in the UI in this case.
I have already looked at PackageManager.hasSystemFeature(), but didn't find anything useful there.
Has anyone already done this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
请参阅
ViewConfiguration#hasPermanentMenuKey()
了解更多信息。请注意,这仅适用于 API 级别 14+(Android 4.0 Ice Cream Sandwich 或更高版本)。See
ViewConfiguration#hasPermanentMenuKey()
for more information. Note that this is only available for API level 14+ (Android 4.0 Ice Cream Sandwich or newer).即使在运行 Honeycomb 及更高版本的设备上,系统也会为针对 2.x 版本 Android 编写的应用程序提供“菜单按钮”。只是它被称为“溢出菜单”。因此,没有必要检查是否有这样的按钮——如果需要的话,它就会在那里。
作为一般准则,您应该检查特定功能,而不是查看系统/API 版本号。如果可用,请使用 ActionBar 类,否则回退到 2.x 选项菜单。
您看过Google 操作栏教程吗?这会让你更清楚你应该做什么。
Even on devices running Honeycomb and later, the system will supply a “Menu button” for apps written for 2.x versions of Android. Only it’s called the “overflow menu”. So there’s no point checking whether there will be such a button or not—it will be there if it’s needed.
As a general guideline, you should check for specific functionality, not look at system/API version numbers. Use the ActionBar class if it’s available, otherwise fallback to the 2.x options menu.
Have you looked at Google’s action-bar tutorial? That makes it clearer what you should be doing.
我认为一个可能的更好的解决方案是添加一个自己的操作栏。因此每个设备都可以看到它,您无需检查硬件配置或 Api 版本。
I think a possible and better solution is to add a own actionbar. So every device can see it and you don't have to check hardware configuration or Api version.
keysoft 限定符用于检测硬件键盘而不是导航栏。
本文解决了这个问题:
检查导航栏
keysoft qualifier is used to detect a hardware keyboard not the navigation bar.
This article solves it:
Check for navigation bar
如果您需要资源限定符(由于您想要区分 UI,可能会出现这种情况),请使用
keyssoft
资源限定符。If you want a resource qualifier, which might be the case since you want to differentiate UIs, use
keyssoft
resource qualifier.