前言 欢迎大家我分享和推荐好用的代码段~~声明 欢迎转载,但请保留文章原始出处: CSDN:
雨季o莫忧离:/luckkof
正文
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
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);
}
}