对于我的一个应用程序,当我的手机从配对设备的区域限制移动时,我需要关闭蓝牙,我的意思是一旦不在限制范围内,只有一个配对设备我需要自动关闭蓝牙。
private void setUpConnection() {
// TODO Auto-generated method stub
// Connect to a particular Bluetooth device
mBluetoothDevice = mBluetoothAdapter
.getRemoteDevice("00:12:06:04:90:72");
// mBluetoothDevice = mBluetoothAdapter.getRemoteDevice("");
try {
mBluetoothSocket = mBluetoothDevice
.createRfcommSocketToServiceRecord(uuid);
mBluetoothSocket.connect();
//flag = 1;
//listen to blue-tooth: Read
Handler handler = new Handler();
BluetoothSocketListener bsl = new BluetoothSocketListener(
mBluetoothSocket, handler);
Thread messageListener = new Thread(bsl);
messageListener.start();
//read json data - remote content
getJsonData();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(getApplicationContext(),
"Power On Bluetooth Device", Toast.LENGTH_LONG).show();
}
}