0

我正在通过 Android Developer 网站上给出的 SafetyNet API 在 android 上使用 reCaptcha API。我的应用程序是多语言应用程序。当我一起更改手机语言设置时,我的 reCaptcha 会以该语言显示。但我想根据应用程序级别的选定区域设置更改语言,而不更改手机语言设置。谷歌文档在这里给出了语言代码。谁能帮我实现这件事。任何帮助或任何建议将不胜感激。

这是我当前的代码。这非常适用于默认电话语言。

private fun verifyGoogleReCAPTCHA() {
    SafetyNet.getClient(this)
        .verifyWithRecaptcha(CAPTCHA_API_SITE_KEY)
        .addOnSuccessListener(this@LoginActivity as Activity) { response ->
            // Indicates communication with reCAPTCHA service was
            // successful.
            val userResponseToken = response.tokenResult
            if (response.tokenResult?.isNotEmpty() == true) {
                // Validate the user response token using the
                // reCAPTCHA siteverify API.
                Log.v("token", userResponseToken)
                handleVerification(userResponseToken)
            }
        }
        .addOnFailureListener(this@LoginActivity as Activity){ e ->
            if (e is ApiException) {
                // An error occurred when communicating with the
                // reCAPTCHA service. Refer to the status code to
                // handle the error appropriately.
                Log.v("Error", "Error: ${CommonStatusCodes.getStatusCodeString(e.statusCode)}")
                Toast.makeText(
                    this,
                    "Error: ${CommonStatusCodes.getStatusCodeString(e.statusCode)}",
                    Toast.LENGTH_LONG
                ).show()
            } else {
                // A different, unknown type of error occurred.
                Log.d("Error", "Error: ${e.message}")
                Toast.makeText(this, "Error: ${e.message}", Toast.LENGTH_LONG).show()
            }
        }
}
4

0 回答 0