gpt4 book ai didi

android - 如何检测 Android 设备是否有软件 key ? (hasPermanentMenuKey 不是解决方案)

转载 作者:行者123 更新时间:2023-11-30 02:45:35 25 4
gpt4 key购买 nike

我需要知道运行我的应用程序的设备是否有导航栏。

hasPermanentMenuKey 不是解决方案,因为有些设备(例如三星 S5)没有导航栏,但也没有菜单键。

有什么方法可以获取这些信息吗?甚至可能在 build.prop 中获取 qemu.hw.mainkeys 的值的方法也是一个解决方案......

谢谢!

最佳答案

试试这个

public static boolean hasNavBar(Context context)
{
Resources res = context.getResources();
int resourceId = res.getIdentifier(SHOW_NAV_BAR_RES_NAME, "bool", "android");

if (resourceId != 0)
{
String sNavBarOverride = "";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
{
try
{
Class c = Class.forName("android.os.SystemProperties");
Method m = c.getDeclaredMethod("get", String.class);
m.setAccessible(true);
sNavBarOverride = (String) m.invoke(null, "qemu.hw.mainkeys");
}
catch (Throwable e)
{
sNavBarOverride = "";
}
}
boolean hasNav = res.getBoolean(resourceId);
// check override flag (see static block)
if ("1".equals(sNavBarOverride))
hasNav = false;
else if ("0".equals(sNavBarOverride))
hasNav = true;
return hasNav;
}
else
{ // fallback
return !ViewConfiguration.get(context).hasPermanentMenuKey();
}
}

关于android - 如何检测 Android 设备是否有软件 key ? (hasPermanentMenuKey 不是解决方案),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25097647/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com