0

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

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

1 回答 1

0

您可以使用以下代码关闭活动的蓝牙

BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();    
if (mBluetoothAdapter.isEnabled()) 
{
    mBluetoothAdapter.disable(); 
} 
于 2013-07-29T04:53:08.350 回答