天天看點

android 判斷藍牙耳機是否連接配接,Android 檢測是否連接配接藍牙耳機 -電腦資料

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

private void handleHeadsetStateChange()

{

Intent intent = new Intent(Intent.ACTION_HEADSET_PLUG);

if(BluetoothProfile.STATE_CONNECTED == adapter.getProfileConnectionState(BluetoothProfile.HEADSET))

{

intent.putExtra("state", 1);

intent.putExtra("microphone", 1);

mContext.sendBroadcast(intent);

}

else if(BluetoothProfile.STATE_DISCONNECTED == adapter.getProfileConnectionState(BluetoothProfile.HEADSET))

{

intent.putExtra("state", -1);

mContext.sendBroadcast(intent);

}

}