๐Ÿ” Android Security and Privacy

Play Integrity API Explained

Your backend can't tell whether a request came from your genuine app on a genuine device, or from a script, an emulator farm or a modified APK. The Play Integrity API gives your server signals to make that decision. Here's how it works and how to use it without harming legitimate users.

โœ๏ธ Yunok Tech ๐Ÿ“… Updated โฑ 3 min read ๐ŸŽฏ Intermediate
On this page
  1. How it works
  2. The verdicts
  3. Client code (standard request)
  4. Server-side verification
  5. Designing a fair response policy
  6. With Firebase
  7. Use cases
  8. Common mistakes
  9. Frequently asked questions
  10. Conclusion

Fraudsters automate sign-ups, farm promotions, scrape APIs and abuse paid features using modified apps or emulators. Client-side checks are easy to bypass. The Play Integrity API moves the decision to your server, using signed verdicts from Google Play.

How it works

Play Integrity standard request flow The app prepares an integrity token provider in advance. For a sensitive action, it computes a request hash of the action's data and requests an integrity token. The app sends the token with the action to your server. The server decodes the token through Google's API, checks the request hash and verdicts, and decides to allow, step up, or deny. Appprepare provider Apprequest(token, hash) token + action Your serverdecode + verify Google PlaydecodeIntegrityTokenโ†’ verdicts Decision happens on the server: allow, step up (e.g. OTP), limit, or deny.
Never decide on the device. A modified app can lie about anything it computes locally.

The verdicts

VerdictQuestion it answersExample values
Request detailsIs this token for this request?Package name, request hash, timestamp
App integrityIs this your unmodified app, as distributed by Play?PLAY_RECOGNIZED, UNRECOGNIZED_VERSION
Device integrityIs it a genuine, certified Android device?MEETS_DEVICE_INTEGRITY, MEETS_BASIC_INTEGRITY, MEETS_STRONG_INTEGRITY
Account detailsDid the user get the app from Play (licensed)?LICENSED, UNLICENSED
Optional signalsAdditional environment detailsSee current docs (for example app access risk)

Client code (standard request)

IntegrityClient.ktKotlin
class IntegrityClient(context: Context, private val cloudProjectNumber: Long) {
    private val manager = IntegrityManagerFactory.createStandard(context)
    private var provider: StandardIntegrityManager.StandardIntegrityTokenProvider? = null

    /** Call early (e.g. app start); preparation can take a few seconds. */
    suspend fun warmUp() {
        provider = manager.prepareIntegrityToken(
            StandardIntegrityManager.PrepareIntegrityTokenRequest.builder()
                .setCloudProjectNumber(cloudProjectNumber)
                .build()
        ).await()
    }

    /** requestHash binds the token to THIS action (e.g. SHA-256 of "redeem:$couponCode:$userId"). */
    suspend fun token(requestHash: String): String {
        val p = provider ?: run { warmUp(); provider!! }
        return p.request(
            StandardIntegrityManager.StandardIntegrityTokenRequest.builder()
                .setRequestHash(requestHash)
                .build()
        ).await().token()
    }
}

Server-side verification

  1. Receive the token with the action payload.
  2. Call Google's decodeIntegrityToken API using service-account credentials (server only).
  3. Check that package name and request hash match this exact action, and that the timestamp is recent.
  4. Evaluate the app, device and account verdicts against your risk policy.
  5. Decide: allow, require step-up (OTP, CAPTCHA, review), rate-limit, or deny.

Designing a fair response policy

  • Tier by risk: require integrity for redeeming money or high-value promotions, not for reading articles.
  • Don't hard-block too eagerly: some legitimate users have older or uncertified devices. Prefer step-up or limited functionality.
  • Handle API errors gracefully: network issues or outdated Play services shouldn't lock users out. Retry or fall back to other checks.
  • Monitor verdict distributions to tune your thresholds.

With Firebase

If your backend is Firebase (Firestore, Functions, AI Logic), App Check with the Play Integrity provider applies integrity checks to Firebase requests for you. See Gemini API Integration for an example.

Use cases

Promotion abuse

Require good device and app integrity for referral rewards, and step up for borderline verdicts.

API scraping

Integrity tokens on sensitive endpoints, plus rate limits per account.

Paid features

Check app integrity and licensing for premium content unlocks.

Common mistakes

  • Decoding or evaluating the verdict on the device.
  • Not binding tokens to the request (missing request hash), which enables replay.
  • Calling the API on every request. Use it for sensitive actions, within quota.
  • Blocking all users on API errors.

Frequently asked questions

Is Play Integrity the replacement for SafetyNet Attestation?

Yes. SafetyNet Attestation was deprecated in favour of the Play Integrity API.

Does it work for apps not installed from Play?

Verdicts will reflect that, for example as unrecognized or unlicensed. Decide how your policy treats sideloaded installs.

Are there usage limits?

Yes, there are daily quotas, which can be increased on request. Check the current documentation and design calls around sensitive actions.

Conclusion

Play Integrity gives your server trustworthy signals about the app, device and account behind a request. Bind tokens to actions with request hashes, verify server-side, apply a graduated risk policy, and handle errors without punishing legitimate users.

Next step: review the threats it helps with in Common Android Security Vulnerabilities.

Official references

๐Ÿ“ฑ Apps built by Yunok Tech

Real Android apps on Google Play, free to download.

See all our apps โ†’

Ready to build real Android applications?

Security is easiest to get right when it is part of how you build from the first screen. Strengthen the Android fundamentals that secure, privacy-respecting apps are built on.

Move beyond theory and strengthen your Android development skills with Yunoktech's Android course. Learn core concepts, practical implementation, modern Android development techniques, and the reasoning behind building maintainable applications.

Explore the Android course and take your next step as an Android developer.

Share: LinkedIn X / Twitter WhatsApp