2013-07-29 15 views
0

对于我的一个应用程序,我需要关掉蓝牙,当我的手机从配对设备的区域限制移动,我的意思是只会有一个配对的设备一旦没有限制,我需要自动关闭蓝牙。如何关闭蓝牙,当配对的设备不在区域限制在android

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(); 
      } 
} 

回答

0

您可以使用下面的代码以关闭的活动蓝牙快速回复

BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();  
if (mBluetoothAdapter.isEnabled()) 
{ 
    mBluetoothAdapter.disable(); 
} 
+0

谢谢,我这样做,但我需要把只有当设备从区域限制搬走它的配对设备。 – Khushi

+0

当然,你可以上传你的代码吗? – Vigbyor

+0

我可以让你的IM(邮件ID),以便我可以分享我的代码! – Khushi