蓝牙的知识点


***************************蓝牙有三中协议:
BluetoothA2dp //声音服务(蓝牙耳机) :车机向耳机传递声音数据
BluetoothA2dpSink  //蓝牙音乐服务 (媒体音频) ; 有播放,上下一曲等功能,例如手机向车机传递 音乐数据
BluetoothHeadsetClient //蓝牙电话服务( 通话 );它的附属协议 pbap协议,里面包含有联系人等
初始化  BluetoothAdapter.getDefaultAdapter().getProfileProxy(BoardApplication.getContext(), new A2dpListener(), BluetoothProfile.A2DP);//耳机

private final class A2dpListener implements BluetoothProfile.ServiceListener { @Override public void onServiceConnected(int profile, BluetoothProfile proxy) {}//连接上蓝牙服务

@Override public void onServiceDisconnected(int profile) {}
}
 

BluetoothAdapter.getDefaultAdapter().getProfileProxy(BoardApplication.getContext(), new A2dpSinkListener(), BluetoothProfile.A2DP_SINK); //蓝牙音乐

private final class A2dpSinkListener implements BluetoothProfile.ServiceListener { @Override public void onServiceConnected(int profile, BluetoothProfile proxy) {}//连接上蓝牙服务

@Override public void onServiceDisconnected(int profile) {}
}

BluetoothAdapter.getDefaultAdapter().getProfileProxy(BoardApplication.getContext(), new HeatsetClientListener(), BluetoothProfile.HEADSET_CLIENT);//蓝牙电话

private final class HeatsetClientListener implements BluetoothProfile.ServiceListener { @Override public void onServiceConnected(int profile, BluetoothProfile proxy) {}//连接上蓝牙服务

@Override public void onServiceDisconnected(int profile) {}
}

蓝牙开关打开之后, 已配对列表: BluetoothAdapter.getBondedDevices
***************************蓝牙的广播
BluetoothAdapter.ACTION_STATE_CHANGED //蓝牙开关状态
          (BluetoothAdapter.EXTRA_STATE)
           BluetoothAdapter.STATE_TURNING_OFF  //正在关闭状态
                   BluetoothAdapter.STATE_OFF //关闭
                   BluetoothAdapter.STATE_TURNING_ON //正在开启状态
                   BluetoothAdapter.STATE_ON //开启
BluetoothDevice.ACTION_PAIRING_REQUEST //请求配对
BluetoothDevice.ACTION_BOND_STATE_CHANGED //配对状态变化
BluetoothDevice.ACTION_PAIRING_CANCEL  //取消配对                   
BluetoothDevice.ACTION_ACL_DISCONNECTED  //远程的断开状态 ,蓝牙距离远导致的断开.(注:系统因为距断开蓝牙依旧会发送断开蓝牙的广播)
BluetoothDevice.ACTION_ACL_CONNECTED  //远程的连接状态   
BluetoothHeadsetClient.ACTION_AG_EVENT  //手机蓝牙连接之后,获取的手机电量
BluetoothHeadsetClient.ACTION_CONNECTION_STATE_CHANGED //电话连接状态更改
BluetoothA2dpSink.ACTION_CONNECTION_STATE_CHANGED //音乐连接状态更改
BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED //耳机连接状态更改
BluetoothAdapter.ACTION_SCAN_MODE_CHANGED //蓝牙的扫描模式
BluetoothAdapter.ACTION_DISCOVERY_STARTED//开始扫描
BluetoothAdapter.ACTION_DISCOVERY_FINISHED//扫描结束
BluetoothDevice.ACTION_FOUND //发现设备
BluetoothDevice.ACTION_NAME_CHANGED//本机蓝牙名称变更
BluetoothDevice.ACTION_UUID//支持carplay
***************************获取蓝牙状态
mBluetoothAdapter.getProfileConnectionState(BluetoothProfile.A2DP);//可操控蓝牙设备,如带播放暂停功能的蓝牙耳机
bluetoothAdapter.getProfileConnectionState(BluetoothProfile.A2DP_SINK);//媒体协议
bluetoothAdapter.getProfileConnectionState(BluetoothProfile.HEADSET_CLIENT);//通话协议
BluetoothA2dpSink/BluetoothHeadsetClient/BluetoothA2dp  .disconnect  断开该服务的连接

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值