开发者

How to get information about CONNECTED bluetooth device for android?

If I have a Android phone which is already connected with a bluetooth headset (paired and connected) to it. How I can get information about that specif开发者_开发知识库ic headset.

Using getBondedDevices() method I get list of all paired devices..I need information about CONNECTED device only.

I can not wait for broadcast receiver to check status, because I need this information at the start of my application. So please suggest is there any way to get this information without waiting for broadcast.


You can do this through the IBluetoothA2dp interface in API 11 and up. Some more info on there is here: Android connect to a paired bluetooth headset

Here is a great resource to see the difference in what is available to this interface between API 10 and 11 where it changed quite a bit. http://grepcode.com/file_/repository.grepcode.com/java/ext/com.google.android/android/4.0.1_r1/android/bluetooth/BluetoothA2dp.java/?v=diff&id2=2.2_r1.1

Hope that helps.


You can use the getConnectedDevices for the HEADSET Profile to get the device to which it is connected.


Check this out to see if headset is connected (ICS only):

    public boolean isVoiceConnected()
    {
        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;
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜