5分以内に再接続されたとき,通知をキャンセルするように
This commit is contained in:
parent
286c178f7f
commit
da545e4a5e
|
@ -28,6 +28,9 @@ import com.google.firebase.firestore.FirebaseFirestore;
|
||||||
|
|
||||||
public class TestService extends Service {
|
public class TestService extends Service {
|
||||||
|
|
||||||
|
private Handler handler = new Handler();
|
||||||
|
private Runnable notificationRunnable;
|
||||||
|
|
||||||
public static class NotificationContent {
|
public static class NotificationContent {
|
||||||
private final String title;
|
private final String title;
|
||||||
private final String description;
|
private final String description;
|
||||||
|
@ -266,16 +269,24 @@ public class TestService extends Service {
|
||||||
SharedPreferences.Editor e = pref.edit();
|
SharedPreferences.Editor e = pref.edit();
|
||||||
String action = intent.getAction(); // may need to chain this to a recognizing function
|
String action = intent.getAction(); // may need to chain this to a recognizing function
|
||||||
boolean isInCar = pref.getBoolean("isInCarPref", false);
|
boolean isInCar = pref.getBoolean("isInCarPref", false);
|
||||||
if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action) && !isInCar) {//bluetoothが切断されたときに乗車状態のとき
|
if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action) && !isInCar) {
|
||||||
// 5分待機する
|
// bluetoothが切断されたときに乗車状態のとき
|
||||||
Handler handler = new Handler();
|
notificationRunnable = new Runnable() {
|
||||||
handler.postDelayed(new Runnable() {
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
// 5分経過した時点でも車に乗っていない場合
|
||||||
Notification(context, BLUETOOTH_NOTIFICATION);
|
Notification(context, BLUETOOTH_NOTIFICATION);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
}, 5 * 60 * 1000); // 5分をミリ秒に変換
|
handler.postDelayed(notificationRunnable, 5 * 60 * 1000); // 5分をミリ秒に変換
|
||||||
|
} else if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) {
|
||||||
|
// 再接続された場合、通知をキャンセルする
|
||||||
|
if (notificationRunnable != null) {
|
||||||
|
handler.removeCallbacks(notificationRunnable);
|
||||||
|
notificationRunnable = null;
|
||||||
|
Log.d("BT", "Notification canceled due to reconnection");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user