SafetyNetApi
Stay organized with collections
Save and categorize content based on your preferences.
The main entry point for interacting with SafetyNet.
Public Methods
This method was deprecated.
use
verifyWithRecaptcha(String)
.
Provides user attestation with reCAPTCHA.
If reCAPTCHA is confident that this is a real user on a real device it will return a
token with no challenge. Otherwise it will provide a visual/audio challenge to attest
the humanness of the user before returning a token.
When you make a request with this API, you must provide your client GoogleApiClient
and site public key as parameters, and after the request completes, you can get the
SafetyNetApi.RecaptchaTokenResult
from the response.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-10-31 UTC.
[null,null,["Last updated 2024-10-31 UTC."],[[["\u003cp\u003e\u003ccode\u003eSafetyNetApi\u003c/code\u003e is the primary interface for interacting with the SafetyNet service on Android.\u003c/p\u003e\n"],["\u003cp\u003eIt offers various functionalities such as attestation, harmful app detection, reCAPTCHA verification, and safe browsing checks through nested classes and methods.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003everifyWithRecaptcha\u003c/code\u003e method, now deprecated, provided user attestation using reCAPTCHA but has been replaced with a newer implementation.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can access different aspects of SafetyNet, like checking device compatibility or verifying user authenticity, via the methods and classes within this API.\u003c/p\u003e\n"],["\u003cp\u003eAlthough deprecated methods exist within this API, they point to newer alternatives for developers to utilize.\u003c/p\u003e\n"]]],["SafetyNetApi facilitates interactions for device safety and user attestation. It returns responses for attestation, harmful apps, reCAPTCHA tokens, safe browsing, and user app verification. The `verifyWithRecaptcha` method, now deprecated, used a `GoogleApiClient` and site key to provide user attestation via reCAPTCHA, returning a token. SafetyNetApi now uses `SafetyNetClient` methods such as `verifyWithRecaptcha(String)` `attest(byte[], String)`, `listHarmfulApps()`, `lookupUri(String, String, int...)` to provide reCAPTCHA, app attestations, harmful app lists and safe browsing results.\n"],null,["# SafetyNetApi\n\npublic interface **SafetyNetApi** \nThe main entry point for interacting with SafetyNet. \n\n### Nested Class Summary\n\n|-----------|---|---|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| class | [SafetyNetApi.AttestationResponse](/android/reference/com/google/android/gms/safetynet/SafetyNetApi.AttestationResponse) || Response from [attest(byte[], String)](/android/reference/com/google/android/gms/safetynet/SafetyNetClient#attest(byte[], java.lang.String)) that contains a [Compatibility Test Suite](//source.android.com/compatibility/cts-intro.html) attestation result. |\n| class | [SafetyNetApi.HarmfulAppsResponse](/android/reference/com/google/android/gms/safetynet/SafetyNetApi.HarmfulAppsResponse) || A [Response](/android/reference/com/google/android/gms/common/api/Response) returned from [listHarmfulApps()](/android/reference/com/google/android/gms/safetynet/SafetyNetClient#listHarmfulApps()). |\n| class | [SafetyNetApi.RecaptchaTokenResponse](/android/reference/com/google/android/gms/safetynet/SafetyNetApi.RecaptchaTokenResponse) || [Response](/android/reference/com/google/android/gms/common/api/Response) from [verifyWithRecaptcha(String)](/android/reference/com/google/android/gms/safetynet/SafetyNetClient#verifyWithRecaptcha(java.lang.String)). |\n| interface | [SafetyNetApi.RecaptchaTokenResult](/android/reference/com/google/android/gms/safetynet/SafetyNetApi.RecaptchaTokenResult) || *This interface was deprecated. use [SafetyNetApi.RecaptchaTokenResponse](/android/reference/com/google/android/gms/safetynet/SafetyNetApi.RecaptchaTokenResponse) returned from [verifyWithRecaptcha(String)](/android/reference/com/google/android/gms/safetynet/SafetyNetClient#verifyWithRecaptcha(java.lang.String)).* |\n| class | [SafetyNetApi.SafeBrowsingResponse](/android/reference/com/google/android/gms/safetynet/SafetyNetApi.SafeBrowsingResponse) || [Response](/android/reference/com/google/android/gms/common/api/Response) for [lookupUri(String, String, int...)](/android/reference/com/google/android/gms/safetynet/SafetyNetClient#lookupUri(java.lang.String, java.lang.String, int...)). |\n| class | [SafetyNetApi.VerifyAppsUserResponse](/android/reference/com/google/android/gms/safetynet/SafetyNetApi.VerifyAppsUserResponse) || A [Response](/android/reference/com/google/android/gms/common/api/Response) to get user decisions for the Verify Apps API. |\n\n### Public Method Summary\n\n|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract [PendingResult](/android/reference/com/google/android/gms/common/api/PendingResult)\\\u003c[SafetyNetApi.RecaptchaTokenResult](/android/reference/com/google/android/gms/safetynet/SafetyNetApi.RecaptchaTokenResult)\\\u003e | [verifyWithRecaptcha](/android/reference/com/google/android/gms/safetynet/SafetyNetApi#verifyWithRecaptcha(com.google.android.gms.common.api.GoogleApiClient, java.lang.String))([GoogleApiClient](/android/reference/com/google/android/gms/common/api/GoogleApiClient) client, [String](//developer.android.com/reference/java/lang/String.html) siteKey) *This method was deprecated. use [verifyWithRecaptcha(String)](/android/reference/com/google/android/gms/safetynet/SafetyNetClient#verifyWithRecaptcha(java.lang.String)).* |\n\nPublic Methods\n--------------\n\n#### public abstract [PendingResult](/android/reference/com/google/android/gms/common/api/PendingResult)\\\u003c[SafetyNetApi.RecaptchaTokenResult](/android/reference/com/google/android/gms/safetynet/SafetyNetApi.RecaptchaTokenResult)\\\u003e\n**verifyWithRecaptcha** ([GoogleApiClient](/android/reference/com/google/android/gms/common/api/GoogleApiClient) client, [String](//developer.android.com/reference/java/lang/String.html) siteKey)\n\n**This method was deprecated.** \n\nuse [verifyWithRecaptcha(String)](/android/reference/com/google/android/gms/safetynet/SafetyNetClient#verifyWithRecaptcha(java.lang.String)). \nProvides user attestation with reCAPTCHA.\n\nIf reCAPTCHA is confident that this is a real user on a real device it will return a\ntoken with no challenge. Otherwise it will provide a visual/audio challenge to attest\nthe humanness of the user before returning a token.\n\nWhen you make a request with this API, you must provide your client [GoogleApiClient](/android/reference/com/google/android/gms/common/api/GoogleApiClient)\nand site public key as parameters, and after the request completes, you can get the\n[SafetyNetApi.RecaptchaTokenResult](/android/reference/com/google/android/gms/safetynet/SafetyNetApi.RecaptchaTokenResult) from the response. \n\n##### Parameters\n\n| client | The [GoogleApiClient](/android/reference/com/google/android/gms/common/api/GoogleApiClient) to service the call. The client must be connected using [connect()](/android/reference/com/google/android/gms/common/api/GoogleApiClient#connect()) before invoking this method. |\n| siteKey | A site public key registered for this app at \u003c//g.co/recaptcha/androidsignup\u003e |\n|---------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|"]]