如何在Android 2.2+上检测免提装饰?

时间:2012-10-26 12:45:44

标签: android

我想知道用户何时连接了免提配件并且没有阻止来电\短信。是否有可能知道它何时通过硬件端口或蓝牙连接?

1 个答案:

答案 0 :(得分:2)

在onCreate或onResume中尝试此操作。

    BluetoothAdapter myLocalAdapter = BluetoothAdapter.getDefaultAdapter();
    BluetoothDevice garniture;
    Set<BluetoothDevice> connectedDevices = myLocalAdapter.getBondedDevices();
    for (BluetoothDevice device : connectedDevices){
        String name = device.getName();
        //...  check for the name you want
        if( name.equals("whatnameisit"){
             garniture = device
        } 
    }
    if (garniture != null){
        // yay we found it,  lets do our work with the device here 
    }