Merge pull request #22 from child-guardian/kyou/Bluetooth

Kyou/bluetooth
This commit is contained in:
Asura146 2024-01-23 02:15:51 +09:00 committed by GitHub
commit 660d8a772a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -260,11 +260,13 @@ public class TestService extends Service {
} }
String deviceHardwareAddress = device.getAddress(); // MAC address String deviceHardwareAddress = device.getAddress(); // MAC address
String registeredId = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("bluetooth_device_id", "none");
if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) { if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) {
//Do something if connected //Do something if connected
Log.d("BT", "Device connected"); Log.d("BT", "Device connected");
String registeredId = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("bluetooth_device_id", "none");
Log.d("BT_Judge", "Registered: " + registeredId); Log.d("BT_Judge", "Registered: " + registeredId);
@ -280,8 +282,12 @@ public class TestService extends Service {
} else if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action)) { } else if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action)) {
//Do something if disconnected //Do something if disconnected
Log.d("BT", "Device disconnected"); if (deviceHardwareAddress.equals(registeredId)) {
Log.d("BT_Judge", "登録済み切断");
e.putBoolean("connection_status",false); e.putBoolean("connection_status",false);
}
Log.d("BT", "Device disconnected");
e.apply(); e.apply();
NotificationBluetooth(getApplicationContext()); NotificationBluetooth(getApplicationContext());