Android Studio 3中Executor编译错误

Pan*_*kaj 3 android-studio-3.1

我的代码如下并遵循本文在 Android Studio 3 中实现 Recaptcha: https: //developer.android.com/training/safetynet/recaptcha.html

btn_Login.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(final View view) {
        SafetyNet.getClient(this).verifyWithRecaptcha("api key")
            .addOnSuccessListener((Executor) this,
                    new OnSuccessListener<SafetyNetApi.RecaptchaTokenResponse>() {
                        @Override
                        public void onSuccess(SafetyNetApi.RecaptchaTokenResponse response) {
                            String userResponseToken = response.getTokenResult();
                            if (!userResponseToken.isEmpty()) {
                            }
                        }
                    })
            .addOnFailureListener((Executor) this, new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    if (e instanceof ApiException) {
                        ApiException apiException = (ApiException) e;
                        int statusCode = apiException.getStatusCode();
                    } else {
                    }
                }
            });

    }
});
Run Code Online (Sandbox Code Playgroud)

我遇到下面的编译错误。

不可转换类型:无法将匿名 android.view.view.onclicklistener 转换为 java.util.concurrent.executor

我错过了什么吗?

Pan*_*kaj 5

我使用了下面的代码,现在一切正常。

确保在活动中实现Executor

btn_Login.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(final View view) {
        SafetyNet.getClient(Activity.this).verifyWithRecaptcha("")
            .addOnSuccessListener((Activity) MyActivity.this,
                new OnSuccessListener<SafetyNetApi.RecaptchaTokenResponse>() {
                    @Override
                    public void onSuccess(SafetyNetApi.RecaptchaTokenResponse response) {
                        // Indicates communication with reCAPTCHA service was
                        // successful.
                        String userResponseToken = response.getTokenResult();
                        if (!userResponseToken.isEmpty()) {
                            // Validate the user response token using the
                            // reCAPTCHA siteverify API.
                        }
                    }
                })
            .addOnFailureListener((Activity) MyActivity.this, new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    if (e instanceof ApiException) {
                        // An error occurred when communicating with the
                        // reCAPTCHA service. Refer to the status code to
                        // handle the error appropriately.
                        ApiException apiException = (ApiException) e;
                        int statusCode = apiException.getStatusCode();

                    } else {
                    }
                }
            });
    }
});
Run Code Online (Sandbox Code Playgroud)