androidRequestIntegrityToken method

  1. @override
Future<AndroidIntegrityResult> androidRequestIntegrityToken(
  1. int? cloudProjectNumber,
  2. String data
)
override

Requests an Android Play Integrity API token for app verification.

This method initiates a Play Integrity check to verify the app's authenticity, device integrity, and licensing status. The integrity token can be used to validate that the app is running on a genuine Android device and has not been tampered with.

Parameters:

  • cloudProjectNumber: Optional Google Cloud project number for enhanced verification. If provided, enables additional Play Console integration features.
  • data: Challenge data to include in the integrity request for replay protection

Returns a Future that completes with an AndroidIntegrityResult containing the integrity token and verification status.

Throws:

Example:

final result = await device.androidRequestIntegrityToken(
  123456789, // Your Google Cloud project number
  base64Encode(utf8.encode('nonce-data')),
);

if (result.isValid) {
  print('Device integrity verified');
  print('Token: ${result.token}');
} else {
  print('Integrity check failed: ${result.error}');
}

Implementation

@override
Future<AndroidIntegrityResult> androidRequestIntegrityToken(
  int? cloudProjectNumber,
  String data,
) async {
  final result = await methodChannel.invokeMapMethod<String, dynamic>(
    "androidRequestIntegrityToken",
    {"cloudProjectNumber": cloudProjectNumber, "data": data},
  );
  return AndroidIntegrityResult.fromJson(result!);
}