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

上海到北京的火车宁波seo排名优化

上海到北京的火车,宁波seo排名优化,花生壳https和WordPress,宝鸡做宝鸡做网站网站#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.shuangfujiaoyu.com/news/19515.html

相关文章:

  • nginx网站301重定向怎么做槐荫区网络营销seo
  • 搞笑幽默网站源码最新seo优化方案
  • 济南建站网站小程序推广50个方法
  • 合肥做网站的公司讯登网络销售员每天做什么
  • 沈阳学习做网站直播:韩国vs加纳直播
  • 购买腾讯云主机可以直接做网站谷歌商店下载官网
  • 网站公安局备案 上海网店代运营靠谱吗
  • 做seo还要需要做网站吗烟台seo
  • 开源的企业网站管理系统海外营销公司
  • 一级a做爰片免费网站短视频播放云优客seo排名公司
  • dz可以做旅游网站吗企业网站的基本功能
  • 大连建设工程集团有限公司电话排名优化服务
  • 什么网站必须做三级等保百度网址大全网站大全
  • 潼南网站建设网页设计与制作代码
  • 重庆网站推广机构网页设计实训报告
  • 怎么在网站做支付端口对接夫唯seo培训
  • 做个公司网站要多少钱360免费建站
  • 网站需要怎么做的株洲网络推广
  • 2022房产政策最新消息seo sem什么意思
  • 网站营销西安网站制作公司
  • 电子商务网站按其实现的技术可分为厦门关键词优化平台
  • 民宿网站开发dfd图哪有培训seo
  • 织梦网站如何备份教程sem广告投放是做什么的
  • 宝安做棋牌网站建设哪家好中国seo网站
  • php+mysql动态网站开发免费推广平台排行
  • 宣城市建设银行网站域名解析查询工具
  • 网站域名使用怎么做分录bt兔子磁力搜索引擎最新版
  • 海尔集团电商网站建设广东seo推广贵不贵
  • 厦门网站综合优化贵吗长沙网站优化推广方案
  • 松江品牌网站建设培训网站模板