Na tej stronie opisujemy, jak postępować w przypadku problemów z ocenami integralności.
Po otrzymaniu żądania tokena integralności możesz wyświetlić użytkownikowi okno Google Play. Możesz wyświetlić okno, gdy wystąpi co najmniej 1 problem z oceną integralności. Okno wyświetla się u góry aplikacji i prosi użytkowników o rozwiązanie problemu. Po zamknięciu okna możesz sprawdzić, czy problem został rozwiązany, wysyłając kolejne żądanie do interfejsu Integrity API.
Okna dotyczące integralności
GET_LICENSED (kod typu 1)
Problem z decyzją
Kiedy appLicensingVerdict == "UNLICENSED"
. Oznacza to, że konto użytkownika
nie ma licencji. To znaczy, że nie zainstalował ani nie kupił jej w Google Play.
Działania naprawcze
Możesz wyświetlić okno GET_LICENSED
, aby poprosić użytkownika o pobranie aplikacji z Google Play. Jeśli użytkownik zaakceptuje zaproszenie, jego konto otrzyma licencję (appLicensingVerdict == "LICENSED"
). Aplikacja zostanie dodana do jego biblioteki Google Play i Google Play będzie mógł dostarczać aktualizacje aplikacji w Twoim imieniu.
Przykładowy UX
Poproś o okno integralności
Gdy klient wysyła żądanie tokena integralności, możesz użyć metody oferowanej w interfejsach StandardIntegrityToken (standardowy interfejs API) i IntegrityTokenResponse (klasyczny interfejs API): showDialog(Activity activity, int integrityDialogTypeCode)
.
Aby wyświetlić okno GET_LICENSED, wykonaj te czynności:
Poproś aplikację o wygenerowanie tokena integralności i wyślij go na swój serwer. Możesz użyć żądania standardowego lub klasycznego.
Kotlin
// Request an integrity token val tokenResponse: StandardIntegrityToken = requestIntegrityToken() // Send token to app server and get response on what to do next val yourServerResponse: YourServerResponse = sendToServer(tokenResponse.token())
Java
// Request an integrity token StandardIntegrityToken tokenResponse = requestIntegrityToken(); // Send token to app server and get response on what to do next YourServerResponse yourServerResponse = sendToServer(tokenResponse.token());
Na swoim serwerze odszyfruj token integralności i sprawdź pole
appLicensingVerdict
. Może to wyglądać mniej więcej tak:// Licensing issue { ... accountDetails: { appLicensingVerdict: "UNLICENSED" } }
Jeśli token zawiera
appLicensingVerdict: "UNLICENSED"
, odpowiedz klientowi aplikacji, wysyłając żądanie udostępnienia, wyświetli się okno licencjonowania:Kotlin
private fun getDialogTypeCode(integrityToken: String): Int{ // Get licensing verdict from decrypted and verified integritytoken val licensingVerdict: String = getLicensingVerdictFromDecryptedToken(integrityToken) return if (licensingVerdict == "UNLICENSED") { 1 // GET_LICENSED } else 0 }
Java
private int getDialogTypeCode(String integrityToken) { // Get licensing verdict from decrypted and verified integrityToken String licensingVerdict = getLicensingVerdictFromDecryptedToken(integrityToken); if (licensingVerdict.equals("UNLICENSED")) { return 1; // GET_LICENSED } return 0; }
Wywołaj w aplikacji polecenie
showDialog
, używając żądanego kodu pobranego z serwera:Kotlin
// Show dialog as indicated by the server val showDialogType: Int? = yourServerResponse.integrityDialogTypeCode() if (showDialogType != null) { // Call showDialog with type code, the dialog will be shown on top of the // provided activity and complete when the dialog is closed. val integrityDialogResponseCode: Task<Int> = tokenResponse.showDialog(activity, showDialogType) // Handle response code, call the Integrity API again to confirm that // verdicts have been resolved. }
Java
// Show dialog as indicated by the server @Nullable Integer showDialogType = yourServerResponse.integrityDialogTypeCode(); if (showDialogType != null) { // Call showDialog with type code, the dialog will be shown on top of the // provided activity and complete when the dialog is closed. Task<Integer> integrityDialogResponseCode = tokenResponse.showDialog(activity, showDialogType); // Handle response code, call the Integrity API again to confirm that // verdicts have been resolved. }
Okno wyświetla się nad podaną aktywnością. Gdy użytkownik zamknie okno, zadanie zakończy się kodem odpowiedzi.
(Opcjonalnie) Poproś o kolejny token, aby wyświetlić kolejne okna. Jeśli wysyłasz żądania standardowe, musisz ponownie rozgrzać dostawcę tokenów, aby uzyskać nowy wynik.