From efaefe4da3846dd4d891da18eac34af3f5d478ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 16:26:39 +0900 Subject: [PATCH] fix --- .../main/java/com/example/childguard/TestService.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index e1bb01b..fc5eec6 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -72,7 +72,9 @@ public class TestService extends Service { return flags; // IDが初期化されていない場合は何もしない } - createRunningNotificationChannel(); + if (!isNotificationChannelCreated(BACKGROUND_CHANNEL_ID)) { + createRunningNotificationChannel(); + } Intent notificationIntent = new Intent(this, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_IMMUTABLE); Notification notification = new NotificationCompat.Builder(this, BACKGROUND_CHANNEL_ID) @@ -94,7 +96,7 @@ public class TestService extends Service { @Override public void onCreate() { super.onCreate(); - if (!isNotificationChannelCreated()) { + if (!isNotificationChannelCreated(CHANNEL_ID)) { createAlertNotificationChannel(); } } @@ -103,9 +105,9 @@ public class TestService extends Service { * 通知チャネルが作成されているか確認 * @return 通知チャンネルの有無 true: 作成済み false: 未作成 */ - private boolean isNotificationChannelCreated() { + private boolean isNotificationChannelCreated(String channelId) { NotificationManager notificationManager = getSystemService(NotificationManager.class); - return notificationManager.getNotificationChannel(CHANNEL_ID) != null; + return notificationManager.getNotificationChannel(channelId) != null; } /**