TestServiceの全体的なリファクタリング #28
@ -265,27 +265,19 @@ public class TestService extends Service {
 | 
				
			|||||||
            SharedPreferences pref = getSharedPreferences("Bluetooth_situation", MODE_PRIVATE);
 | 
					            SharedPreferences pref = getSharedPreferences("Bluetooth_situation", MODE_PRIVATE);
 | 
				
			||||||
            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) {//bluetoothが切断されたときに乗車状態のとき
 | 
				
			||||||
 | 
					                // 5分待機する
 | 
				
			||||||
                //Do something if disconnected
 | 
					                Handler handler = new Handler();
 | 
				
			||||||
                //デバイスが切断されたときの処理
 | 
					                handler.postDelayed(new Runnable() {
 | 
				
			||||||
                if (deviceHardwareAddress.equals(registeredId)) {
 | 
					                    @Override
 | 
				
			||||||
                    // 5分待機する
 | 
					                    public void run() {
 | 
				
			||||||
                    Handler handler = new Handler();
 | 
					                        if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action) && !isInCar) {//その後bluetoothを再接続したり降車状態になったりしていない=置き去りが発生した可能性大
 | 
				
			||||||
                    handler.postDelayed(new Runnable() {
 | 
					                            Notification(context, BLUETOOTH_NOTIFICATION);
 | 
				
			||||||
                        @Override
 | 
					 | 
				
			||||||
                        public void run() {
 | 
					 | 
				
			||||||
                            if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action) && !isInCar) {//その後bluetoothを再接続したり降車状態になったりしていない=置き去りが発生した可能性大
 | 
					 | 
				
			||||||
                                Notification(context, BLUETOOTH_NOTIFICATION);
 | 
					 | 
				
			||||||
                            }
 | 
					 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    }, 5 * 60 * 1000); // 5分をミリ秒に変換
 | 
					                }, 5 * 60 * 1000); // 5分をミリ秒に変換
 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            } else {
 | 
					 | 
				
			||||||
                Log.d("BT", "Device disconnected");
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user