当前位置: 首页 > news >正文

上海到北京高铁价格查询seo综合查询怎么用的

上海到北京高铁价格查询,seo综合查询怎么用的,整合营销英文,苏州网站建设网络推广#Android9 查看连接多个蓝牙耳机查看使用中的蓝牙耳机 文章目录 一、主要api:二、BluetoothA2dp 对象的获取三、获取 BluetoothDevice 对象,四、其他: Android 9.0之后,支持一台手机可以同时连接多个蓝牙设备。 但是判断那个蓝牙…

#Android9 查看连接多个蓝牙耳机查看使用中的蓝牙耳机

文章目录

    • 一、主要api:
    • 二、BluetoothA2dp 对象的获取
    • 三、获取 BluetoothDevice 对象,
    • 四、其他:

Android 9.0之后,支持一台手机可以同时连接多个蓝牙设备。

但是判断那个蓝牙设备是使用中,需要经过一些复杂判断才知道!

一、主要api:

 boolean a2dpPlaying = BluetoothA2dp.isA2dpPlaying(BluetoothDevice);

看起来不难,但是 BluetoothA2dp 和 BluetoothDevice 如何获取到?

BluetoothA2dp 获取需要连接服务,BluetoothDevice 遍历所有蓝牙即可。

二、BluetoothA2dp 对象的获取

BluetoothA2dp mA2dp;public void initA2dpAdapter() {BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();if (mBluetoothAdapter.isEnabled()) { //判断蓝牙是否开启//获取A2DP代理对象if (mA2dp == null) { //不能重复连接服务,否则会报错mBluetoothAdapter.getProfileProxy(getContext(), mBluetoothProfileListener, BluetoothProfile.A2DP);}} else {LogUtil.error("getA2dpAdapter error. bluetooth is not Enabled");}}//getProfileProxy并不会直接返回A2DP代理对象,而是通过mListener中回调获取。private BluetoothProfile.ServiceListener mBluetoothProfileListener = new BluetoothProfile.ServiceListener() {@Overridepublic void onServiceDisconnected(int profile) {if (profile == BluetoothProfile.A2DP) {LogUtil.error("A2dp onServiceDisconnected ");mA2dp = null;}}// getProfileProxy 到 连接成功一般需要几十毫秒!@Overridepublic void onServiceConnected(int profile, BluetoothProfile proxy) {if (profile == BluetoothProfile.A2DP) {LogUtil.error("A2dp onServiceConnected ");mA2dp = (BluetoothA2dp) proxy; //转换 ,这个就是  BluetoothA2dp 对象//不显示蓝牙界面连接耳机会出现多个连接状态的蓝牙耳机,断开非使用中的蓝牙耳机judgeIsConnectManyBluetooth();}}};

三、获取 BluetoothDevice 对象,

	//判断所有的耳机设备是否存在多个连接状态的private boolean isConnectManyBluetooth() {//未从已连接设备列表中找到断开的api,从所有的设备列表中进行判断连接状态后断开LocalBluetoothManager mBluetoothManager = LocalBluetoothManager.getInstance(context, mOnInitCallback);Collection<CachedBluetoothDevice> cachedDevices = mBluetoothManager.getCachedDeviceManager().getCachedDevicesCopy();LogUtil.debug("cachedDevices size = " + cachedDevices.size());//更新蓝牙列表UIint connectDevices = 0;for (CachedBluetoothDevice cachedDevice : cachedDevices) {String name = cachedDevice.getDevice().getName();if (cachedDevice.isConnected()) {LogUtil.debug("cachedDevices name = " + name);connectDevices++;}if (connectDevices > 1) {return true;}}return false;}//判断是否多个蓝牙连接状态,如果是就断开非使用中的蓝牙private void judgeIsConnectManyBluetooth() {if (isConnectManyBluetooth()) {//获取当前使用中的蓝牙耳机对象,断开其他耳机对象LocalBluetoothManager mBluetoothManager = LocalBluetoothManager.getInstance(context, mOnInitCallback);Collection<CachedBluetoothDevice> cachedDevices = mBluetoothManager.getCachedDeviceManager().getCachedDevicesCopy();LogUtil.debug("cachedDevices size = " + cachedDevices.size());//更新蓝牙列表UIfor (CachedBluetoothDevice cachedDevice : cachedDevices) {String name = cachedDevice.getDevice().getName();if (mA2dp != null && cachedDevice.getDevice() != null) {boolean a2dpPlaying = mA2dp.isA2dpPlaying(cachedDevice.getDevice());  //判断蓝牙是否使用中!if (a2dpPlaying) {LogUtil.debug("cachedDevices a2dpPlaying name = " + name);disconnectOtherExceptOne(name, cachedDevice.getDevice().getBluetoothClass().getMajorDeviceClass());}}}}}

LocalBluetoothManager 这个类是SettingLib 里面的类,如果不是系统源码或者系统应用是调用不到的!可以用反射!

上面是实际项目中的一段代码,其实具体获取 BluetoothDevice api只有个两句:

CachedBluetoothDevice cachedDevice;//单个蓝牙对象
BluetoothDevice  bluetoothDevice = cachedDevice.getDevice();

四、其他:

     //已连接/绑定设备列表Set<BluetoothDevice> bondedDevices = mBluetoothManager.getBluetoothAdapter().getBondedDevices();

BluetoothDevice 对象没有啥连接和断开操作的方法!只有一下配置信息。

http://www.khdw.cn/news/40768.html

相关文章:

  • 专门做图片是网站百度新闻下载安装
  • 四库一平台建造师业绩查询哪家公司做推广优化好
  • 网站设计公司地址百度知道一下
  • 软件开发流程ppt青岛神马排名优化
  • 福州小学网站建设经典软文案例和扶贫农产品软文
  • 怎么将网站设置为首页网站移动端优化工具
  • 公司网站建设工作通知网店推广联盟
  • 网站图片怎样做seo优化深圳全网推广方案
  • 彩票网站为啥链接做两次跳转百度云资源搜索入口
  • 做数学ppt工具的网站知道百度
  • 电子商务公司网站怎么建网络舆情报告
  • 广州网站建设开发公司百度免费安装下载
  • 有什么网上做c 的网站下载百度语音导航地图安装
  • 怎样做自己可以发布消息的网站百度自媒体平台
  • 怎么做简单的网站首页文员短期电脑培训
  • 做照明出口的网站推广服务商
  • 郑州外贸网站建设商家潍坊seo外包平台
  • 网站建设用哪种语言最好网络推广培训去哪里好
  • 门户网站建设工作讲话网络推广营销方案100例
  • 大型网站开发 书籍在线一键生成网页
  • wordpress博客案例信息如何优化上百度首页
  • 建立企业网站的详细步骤最新seo教程
  • 花都建站电商网站分析
  • 晚上做设计挣钱的网站自己怎么建网站
  • 查看网站域名建站系统
  • 台州网站排名优化公司品牌推广工作内容
  • 服务器怎么做网站教程企业网络的组网方案
  • asp.net做网站野狼seo团队
  • wordpress 自动相册seo软件视频教程
  • wordpress 卡密关键词优化软件有哪些