提出段階のver

This commit is contained in:
it232115 2024-01-23 09:29:42 +09:00
parent 75b4be9ff1
commit 235afb92cb
2 changed files with 22 additions and 28 deletions

View File

@ -408,7 +408,7 @@ public class MainActivity extends AppCompatActivity {
NotificationBluetooth(getApplicationContext());//通知を行うメソッド
}}
}, 5 *60 *1000); // 5分をミリ秒に変換
}, 5 *60*1000); // 5分をミリ秒に変換
}
}else {
Log.d("BT", "Device disconnected");

View File

@ -152,12 +152,13 @@ public class TestService extends Service {
}
NotificationManager notificationManager = (NotificationManager)context.getSystemService(context.NOTIFICATION_SERVICE);
NotificationManager notificationManager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
return;
}
notificationManager.notify(R.string.app_name, builder.build());//通知の表示
}
public void NotificationBluetooth(Context context) {//実際に通知を行うメソッド
final String CHANNEL_ID = "my_channel_id";
// 通知がクリックされたときに送信されるIntent
@ -198,7 +199,7 @@ public class TestService extends Service {
}
NotificationManager notificationManager = (NotificationManager)context.getSystemService(context.NOTIFICATION_SERVICE);
NotificationManager notificationManager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
return;
}
@ -206,10 +207,6 @@ public class TestService extends Service {
}
public void Bluetooth_status() {
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED);
@ -232,8 +229,8 @@ public class TestService extends Service {
@Override
public void onReceive(Context context, Intent intent) {
SharedPreferences pref=getSharedPreferences("Bluetooth_situation",MODE_PRIVATE);
SharedPreferences.Editor e=pref.edit();
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);
@ -253,22 +250,21 @@ public class TestService extends Service {
Log.d("BT", "Device connected");
Log.d("BT_Judge", "Registered: " + registeredId);
if (deviceHardwareAddress.equals(registeredId)) {
//登録済みのデバイスだったときの処理
Log.d("BT_Judge", "登録済み");
e.putBoolean("connection_status",true);
e.putBoolean("connection_status", true);
} else{
} else {
//登録していないデバイスだったときの処理
Log.d("BT_Judge", "未登録");
e.putBoolean("connection_status",false);
e.putBoolean("connection_status", false);
}
e.apply();
} else if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action)&&!isInCar) {//bluetoothが切断されたときに乗車状態のとき
} else if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action) && !isInCar) {//bluetoothが切断されたときに乗車状態のとき
//Do something if disconnected
//デバイスが切断されたときの処理
@ -278,22 +274,20 @@ public class TestService extends Service {
handler.postDelayed(new Runnable() {
@Override
public void run() {
if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action)&&!isInCar) {//その後bluetoothを再接続したり降車状態になったりしていない置き去りが発生した可能性大
if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action) && !isInCar) {//その後bluetoothを再接続したり降車状態になったりしていない置き去りが発生した可能性大
NotificationBluetooth(getApplicationContext());//通知を行うメソッド
}}
}, 5 *60 *1000); // 5分をミリ秒に変換
}
}else {
}
}, 5 * 60 * 1000); // 5分をミリ秒に変換
}
} else {
Log.d("BT", "Device disconnected");
}
}
};
@Nullable
@Override
public IBinder onBind(Intent intent) {