From dbbe4b2f1e51c928a00257892f717480eebc00b7 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:48:29 +0900 Subject: [PATCH] =?UTF-8?q?Bluetooth=E9=A7=86=E5=8B=95=E3=81=AE=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E3=81=A8=E9=80=9A=E5=A0=B1=E3=82=92=E5=88=A5=E3=83=81?= =?UTF-8?q?=E3=83=A3=E3=83=B3=E3=83=8D=E3=83=AB=E3=81=AB(=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E3=81=AE=E4=B8=8A=E6=9B=B8=E3=81=8D=E3=81=8C=E8=B5=B7?= =?UTF-8?q?=E3=81=93=E3=82=89=E3=81=AA=E3=81=84=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/childguard/TestService.java | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 6364860..48f0ac3 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -35,10 +35,12 @@ public class TestService extends Service { public static class NotificationContent { private final String title; private final String description; + private final String channelId; - public NotificationContent(String title, String description) { + public NotificationContent(String title, String description, String channelId) { this.title = title; this.description = description; + this.channelId = channelId; } public String getTitle() { @@ -48,19 +50,24 @@ public class TestService extends Service { public String getDescription() { return description; } + + public String getChannelId() { + return channelId; + } } public static final String TAG = "InspirationQuote"; - private static final String CHANNEL_ID = "child_guard_emergency"; + private static final String BT_ALERT_CHANNEL_ID = "child_guard_bt_alert"; + private static final String REPORTED_CHANNEL_ID = "child_guard_reported"; private static final String BACKGROUND_CHANNEL_ID = "child_guard_background"; private static final int REQUEST_CODE = 100; // private static final int NOTIFICATION_DELAY = 5 * 60 * 1000; // 5 minutes // DEBUG private static final int NOTIFICATION_DELAY = 5 * 1000; // 15 seconds private static final NotificationContent REPORTED_NOTIFICATION = - new NotificationContent("子供の置き去りをしていませんか?", "第三者からの通報が行われました。"); + new NotificationContent("子供の置き去りをしていませんか?", "第三者からの通報が行われました。", REPORTED_CHANNEL_ID); private static final NotificationContent BLUETOOTH_NOTIFICATION = - new NotificationContent("子供の置き去りをしていませんか?", "Bluetoothと車の切断から5分が経過しました"); + new NotificationContent("子供の置き去りをしていませんか?", "Bluetoothと車の切断から5分が経過しました", BT_ALERT_CHANNEL_ID); private String userId = null; @@ -96,9 +103,8 @@ public class TestService extends Service { @Override public void onCreate() { super.onCreate(); - if (!isNotificationChannelCreated(CHANNEL_ID)) { - createAlertNotificationChannel(); - } + if (!isNotificationChannelCreated(BT_ALERT_CHANNEL_ID)) createAlertNotificationChannel(BT_ALERT_CHANNEL_ID); + if (!isNotificationChannelCreated(REPORTED_CHANNEL_ID)) createAlertNotificationChannel(REPORTED_CHANNEL_ID); } /** @@ -113,9 +119,9 @@ public class TestService extends Service { /** * 通知チャネルの作成 */ - private void createAlertNotificationChannel() { + private void createAlertNotificationChannel(String channelId) { int importance = NotificationManager.IMPORTANCE_DEFAULT; - NotificationChannel channel = new NotificationChannel(CHANNEL_ID, "通知", importance); + NotificationChannel channel = new NotificationChannel(channelId, "通知", importance); channel.setDescription("第三者により置き去りの通報が行われたときに通知します。"); NotificationManager notificationManager = getSystemService(NotificationManager.class); notificationManager.createNotificationChannel(channel); @@ -263,7 +269,7 @@ public class TestService extends Service { vibrateDevice(); - NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID) + NotificationCompat.Builder builder = new NotificationCompat.Builder(context, content.getChannelId()) .setSmallIcon(android.R.drawable.ic_menu_info_details) .setContentTitle(content.getTitle())//通知のタイトル .setContentText(content.getDescription())//通知の内容