From 3680ead6e168a2db91d8d85f5047c83c64f786fc Mon Sep 17 00:00:00 2001 From: Asura146 Date: Tue, 23 Jan 2024 02:08:38 +0900 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E9=8C=B2=E6=B8=88=E3=81=BF=E3=81=AE?= =?UTF-8?q?=E3=83=87=E3=83=90=E3=82=A4=E3=82=B9=E3=81=8C=E5=88=87=E6=96=AD?= =?UTF-8?q?=E3=81=95=E3=82=8C=E3=81=9F=E3=81=A8=E3=81=8D=E3=81=AE=E5=88=A4?= =?UTF-8?q?=E5=AE=9A=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/example/childguard/TestService.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 436a964..5906c94 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -311,11 +311,13 @@ public class TestService extends Service { } String deviceHardwareAddress = device.getAddress(); // MAC address + String registeredId = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("bluetooth_device_id", "none"); + if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) { //Do something if connected Log.d("BT", "Device connected"); - String registeredId = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("bluetooth_device_id", "none"); + Log.d("BT_Judge", "Registered: " + registeredId); @@ -331,8 +333,12 @@ public class TestService extends Service { } else if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action)) { //Do something if disconnected + if (deviceHardwareAddress.equals(registeredId)) { + Log.d("BT_Judge", "登録済み切断"); + e.putBoolean("connection_status",false); + + } Log.d("BT", "Device disconnected"); - e.putBoolean("connection_status",false); e.apply(); } } -- 2.45.1