如何在Android Q中检测全屏手势模式

Jay*_*ash 11 java android android-10.0

在Android Q中,用户可以启用全屏手势模式。我想检测设备是否处于全屏手势模式。我在文档中找不到任何内容。如何在运行时以编程方式进行操作?

Java或Kotlin语言的答案可以。

任何官方API或解决方法...

Tru*_*oan 18

您可以使用以下代码检查手势或导航模式

    public static int isEdgeToEdgeEnabled(Context context) {
        Resources resources = context.getResources();
        int resourceId = resources.getIdentifier("config_navBarInteractionMode", "integer", "android");
        if (resourceId > 0) {
            return resources.getInteger(resourceId);
        }
        return 0;
    }
Run Code Online (Sandbox Code Playgroud)

isEdgeToEdgeEnabled 函数返回的值如下:

  • 0 : 导航显示有 3 个按钮

  • 1 : 导航显示有 2 个按钮(Android P 导航模式)

  • 2:全屏手势(Android Q上的手势)

  • 重要的!您需要用 try/catch 包围“resources.getInteger()”来处理 Resources.NotFoundException,否则此代码将在各种小米和三星设备上崩溃。此外,此代码不适用于华为设备。 (3认同)
  • 这是行不通的。我在小米设备上尝试过。在手势和菜单按钮模式下都给出 0 (3认同)
  • 使用资源标识符可靠吗?我读到它们因设备而异并且可能会随着时间的推移而改变...... (2认同)