Android 判断蓝牙耳机是否连接

public boolean isBlueToothHeadsetConnected()
    {
        boolean retval = true;
        try {
            retval = BluetoothAdapter.getDefaultAdapter().getProfileConnectionState(android.bluetooth.BluetoothProfile.HEADSET) 
!= android.bluetooth.BluetoothProfile.STATE_DISCONNECTED;

        } catch (Exception exc) {
            // nothing to do
        }
        return retval;
    }

记得不要忘记在AndroidManifest.xml中添加蓝牙耳机权限。

<uses-permission android:name=”android.permission.BLUETOOTH” />

 

http://www.waitingfy.com/?p=673

673

Leave a Reply

Name and Email Address are required fields.
Your email will not be published or shared with third parties.