首页 > 解决方案 > Android reCaptcha 强制纵向定向

问题描述

我正在开发一个需要使用 reCaptcha 验证用户的 Android 应用程序,但我遇到了奇怪的行为:如果屏幕方向为横向,则点击触发 reCaptcha API 方向的按钮将变为纵向,然后再返回横向。

有办法解决这个问题吗?我没有找到任何有关此的文档...

这是来自 SafetyNet 库的 API:

SafetyNet.getClient(this).verifyWithRecaptcha(ReCaptcha.RECAPTCHA_APP_KEY) 

版本:

 implementation("com.google.android.gms:play-services-safetynet:17.0.0")

标签: androidrecaptchasafetynet

解决方案


当您旋转时,您的活动会刷新

您需要在活动标签中声明 android:configChanges="orientation|screenSize"

<activity
         android:configChanges="orientation|screenSize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

这将避免活动刷新我希望这会有所帮助


推荐阅读