From c09ba30fa19b9e382682a4b9a1679eb07f0b87f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Wed, 17 Jan 2024 16:55:05 +0900 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/childguard/MainActivity.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/example/childguard/MainActivity.java b/app/src/main/java/com/example/childguard/MainActivity.java index a8600be..6d0c63a 100644 --- a/app/src/main/java/com/example/childguard/MainActivity.java +++ b/app/src/main/java/com/example/childguard/MainActivity.java @@ -80,17 +80,18 @@ public class MainActivity extends AppCompatActivity { private final ActivityResultLauncher QrLauncher = registerForActivityResult( new ScanContract(), result -> { - if (result != null) { - String url = result.getContents(); - Log.d("QRFragment", "onActivityResult: " + url); - if (url != null) { - Uri uri = Uri.parse(url); - CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); - CustomTabsIntent customTabsIntent = builder.build(); - customTabsIntent.launchUrl(this, uri); - } + String contents = result.getContents(); + if (contents == null) { + Toast.makeText(this, "QRコードが読み取れませんでした", Toast.LENGTH_LONG).show(); + } else if (!contents.contains("https://practicefirestore1-8808c.web.app/")) { + Toast.makeText(this, "Chiled Guardに対応するQRコードではありません", Toast.LENGTH_LONG).show(); } else { - Log.d("QRFragment", "onActivityResult: null"); + //URLの表示 + Toast.makeText(this, contents, Toast.LENGTH_SHORT).show(); + //ブラウザを起動し、URL先のサイトを開く + CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); + CustomTabsIntent customTabsIntent = builder.build(); + customTabsIntent.launchUrl(this, Uri.parse(contents)); } } );