From d53691236f381fd8ed727a9631ef5b9debc1168c 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 15:33:51 +0900 Subject: [PATCH] =?UTF-8?q?=E5=BF=85=E8=A6=81=E3=81=AA=E3=83=87=E3=83=BC?= =?UTF-8?q?=E3=82=BF=E3=81=8C=E3=81=AA=E3=81=84=E5=A0=B4=E5=90=88=E3=81=AA?= =?UTF-8?q?=E3=81=A9=E3=81=AB=E3=81=A7=E3=81=8D=E3=82=8B=E3=81=A0=E3=81=91?= =?UTF-8?q?=E6=97=A9=E3=81=8F=E5=87=A6=E7=90=86=E3=82=92=E4=B8=AD=E6=96=AD?= =?UTF-8?q?=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/childguard/TestService.java | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index f9ab3ee..453f390 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -239,10 +239,33 @@ public class TestService extends Service { @Override public void onReceive(Context context, Intent intent) { + + // 処理対象か確認 ---------------------------------------- + BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); + if (device == null) { + Log.d("BT", "No device found"); + return; + } + String deviceHardwareAddress = device.getAddress(); // MAC address + if (deviceHardwareAddress == null) { + Log.d("BT", "No device address found"); + return; + } + String registeredId = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("bluetooth_device_id", null); + if (registeredId == null) { + Log.d("BT_Judge", "No registered device"); + return; + } + if (!registeredId.equals(deviceHardwareAddress)) { + Log.d("BT_Judge", "Not registered device"); + return; + } + // ----------------------------------------------------- + SharedPreferences pref = getSharedPreferences("Bluetooth_situation", MODE_PRIVATE); SharedPreferences.Editor e = pref.edit(); String action = intent.getAction(); // may need to chain this to a recognizing function - BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); + Boolean isInCar = pref.getBoolean("isInCarPref", false); @@ -250,9 +273,8 @@ public class TestService extends Service { Log.d("BT", "No permission to connect bluetooth devices"); return; } - 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