Android:以编程方式检测设备是否有硬件菜单按钮

发布于 2024-12-29 22:07:10 字数 173 浏览 3 评论 0原文

我目前正在努力解决这个问题。我需要检查安装应用程序的设备是否有硬件菜单键。由于它在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

面如桃花 2025-01-05 22:07:10
ViewConfiguration.get(context).hasPermanentMenuKey()

See ViewConfiguration#hasPermanentMenuKey() for more information. Note that this is only available for API level 14+ (Android 4.0 Ice Cream Sandwich or newer).

那片花海 2025-01-05 22:07:10
if(Build.VERSION.SDK_INT <= 10 || (Build.VERSION.SDK_INT >= 14 &&    
                              ViewConfiguration.get(this).hasPermanentMenuKey()))
{
   // menu key is present
}
else
{
  //No menu key
}
if(Build.VERSION.SDK_INT <= 10 || (Build.VERSION.SDK_INT >= 14 &&    
                              ViewConfiguration.get(this).hasPermanentMenuKey()))
{
   // menu key is present
}
else
{
  //No menu key
}
画中仙 2025-01-05 22:07:10

即使在运行 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.

红焚 2025-01-05 22:07:10

我认为一个可能的更好的解决方案是添加一个自己的操作栏。因此每个设备都可以看到它,您无需检查硬件配置或 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.

摇划花蜜的午后 2025-01-05 22:07:10

keysoft 限定符用于检测硬件键盘而不是导航栏。

本文解决了这个问题:

检查导航栏

keysoft qualifier is used to detect a hardware keyboard not the navigation bar.

This article solves it:

Check for navigation bar

葮薆情 2025-01-05 22:07:10

如果您需要资源限定符(由于您想要区分 UI,可能会出现这种情况),请使用 keyssoft 资源限定符。

If you want a resource qualifier, which might be the case since you want to differentiate UIs, use keyssoft resource qualifier.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文