0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Play Integrity API の「修正ダイアログ」を実装してみたらハマったところ

Last updated at Posted at 2025-11-19

私が作っているAndroidアプリでは、Google Play Integrity API(完全性と署名のチェック)を使っているのですが、最近、なにかのきっかけでGoogleさんのドキュメントを眺めていた時、またなにかアップデートされているのを見つけてしまいました。チェックに引っかかった際、ユーザーを誘導する「修正ダイアログ」を出せるようになったようです。

だいたいの原因は、Google Playストアアプリのバージョンが低いとか、危険と判定されているアプリがインストールされている等、たいしたことではないのですが、一般のユーザーには、その調査力すらないですし、原因に気づいてくれません。
それで、時々、ユーザーからアプリが動かないという問い合わせを受けますが、この修正ダイアログというのに対応すれば少しは減るかもしれません。アプリが動かなくて利用をあきらめる確率も減ると思います。

さっそく実装してみました。
基本的にGoogleさんのドキュメントに従えばいいです。ハマったところがあったので、その部分についてだけ、ここに記録しておきます。

一般的に、Google Play Integrity APIを使う時は、クライアント側(アプリ側)でトークンを取得し、それをサーバーに投げて、サーバー側でチェックして、そのチェック結果をクライアントに返すという流れになると思います。

最初にクライアント側での処理に失敗した場合、ダイアログを出すのと、サーバーからのチェック結果がNGの時にダイアログを出すという、二か所でダイアログを出すことになります。
1.クライアントのNGでダイアログ(上のチャートの1)
2.サーバーのチェックのNGでダイアログ(上のチャートの5)

Googleさんのドキュメントでハマったのが、サーバーからのチェック結果がNGの時にダイアログを出す部分です。最新版に合わせてドキュメントが更新されていないのだと思います。

// クライアントNGでのダイアログ表示
StandardIntegrityDialogRequest standardIntegrityDialogRequest =
	StandardIntegrityDialogRequest.builder()
		.setActivity(this.activity)
		.setType(IntegrityDialogTypeCode.GET_INTEGRITY)
		.setStandardIntegrityResponse(new ExceptionDetails(exception))
		.build();
Task<Integer> responseCode =
	standardIntegrityManager.showDialog(standardIntegrityDialogRequest);
// サーバー結果を受けてダイアログ表示
StandardIntegrityDialogRequest standardIntegrityDialogRequest =
	StandardIntegrityDialogRequest.builder()
		.setActivity(this.activity)
		.setType(IntegrityDialogTypeCode.GET_INTEGRITY)
		.setStandardIntegrityResponse(new StandardIntegrityManager.StandardIntegrityDialogRequest.StandardIntegrityResponse.TokenResponse(standardIntegrityToken))
		.build();
Task<Integer> responseCode =
	standardIntegrityManager.showDialog(standardIntegrityDialogRequest);

setStandardIntegrityResponse部分の違いです。
サーバー結果でダイアログを表示するには、setStandardIntegrityResponseメソッドにexceptionではなく、トークンを渡すことになります。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?