中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁(yè) > news >正文

什么做網(wǎng)站/學(xué)生網(wǎng)頁(yè)制作成品

什么做網(wǎng)站,學(xué)生網(wǎng)頁(yè)制作成品,wordpress 頂端加代碼,小挑可以做網(wǎng)站嗎#Android9 查看連接多個(gè)藍(lán)牙耳機(jī)查看使用中的藍(lán)牙耳機(jī) 文章目錄 一、主要api:二、BluetoothA2dp 對(duì)象的獲取三、獲取 BluetoothDevice 對(duì)象,四、其他: Android 9.0之后,支持一臺(tái)手機(jī)可以同時(shí)連接多個(gè)藍(lán)牙設(shè)備。 但是判斷那個(gè)藍(lán)牙…

#Android9 查看連接多個(gè)藍(lán)牙耳機(jī)查看使用中的藍(lán)牙耳機(jī)

文章目錄

    • 一、主要api:
    • 二、BluetoothA2dp 對(duì)象的獲取
    • 三、獲取 BluetoothDevice 對(duì)象,
    • 四、其他:

Android 9.0之后,支持一臺(tái)手機(jī)可以同時(shí)連接多個(gè)藍(lán)牙設(shè)備。

但是判斷那個(gè)藍(lán)牙設(shè)備是使用中,需要經(jīng)過(guò)一些復(fù)雜判斷才知道!

一、主要api:

 boolean a2dpPlaying = BluetoothA2dp.isA2dpPlaying(BluetoothDevice);

看起來(lái)不難,但是 BluetoothA2dp 和 BluetoothDevice 如何獲取到?

BluetoothA2dp 獲取需要連接服務(wù),BluetoothDevice 遍歷所有藍(lán)牙即可。

二、BluetoothA2dp 對(duì)象的獲取

BluetoothA2dp mA2dp;public void initA2dpAdapter() {BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();if (mBluetoothAdapter.isEnabled()) { //判斷藍(lán)牙是否開(kāi)啟//獲取A2DP代理對(duì)象if (mA2dp == null) { //不能重復(fù)連接服務(wù),否則會(huì)報(bào)錯(cuò)mBluetoothAdapter.getProfileProxy(getContext(), mBluetoothProfileListener, BluetoothProfile.A2DP);}} else {LogUtil.error("getA2dpAdapter error. bluetooth is not Enabled");}}//getProfileProxy并不會(huì)直接返回A2DP代理對(duì)象,而是通過(guò)mListener中回調(diào)獲取。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; //轉(zhuǎn)換 ,這個(gè)就是  BluetoothA2dp 對(duì)象//不顯示藍(lán)牙界面連接耳機(jī)會(huì)出現(xiàn)多個(gè)連接狀態(tài)的藍(lán)牙耳機(jī),斷開(kāi)非使用中的藍(lán)牙耳機(jī)judgeIsConnectManyBluetooth();}}};

三、獲取 BluetoothDevice 對(duì)象,

	//判斷所有的耳機(jī)設(shè)備是否存在多個(gè)連接狀態(tài)的private boolean isConnectManyBluetooth() {//未從已連接設(shè)備列表中找到斷開(kāi)的api,從所有的設(shè)備列表中進(jìn)行判斷連接狀態(tài)后斷開(kāi)LocalBluetoothManager mBluetoothManager = LocalBluetoothManager.getInstance(context, mOnInitCallback);Collection<CachedBluetoothDevice> cachedDevices = mBluetoothManager.getCachedDeviceManager().getCachedDevicesCopy();LogUtil.debug("cachedDevices size = " + cachedDevices.size());//更新藍(lán)牙列表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;}//判斷是否多個(gè)藍(lán)牙連接狀態(tài),如果是就斷開(kāi)非使用中的藍(lán)牙private void judgeIsConnectManyBluetooth() {if (isConnectManyBluetooth()) {//獲取當(dāng)前使用中的藍(lán)牙耳機(jī)對(duì)象,斷開(kāi)其他耳機(jī)對(duì)象LocalBluetoothManager mBluetoothManager = LocalBluetoothManager.getInstance(context, mOnInitCallback);Collection<CachedBluetoothDevice> cachedDevices = mBluetoothManager.getCachedDeviceManager().getCachedDevicesCopy();LogUtil.debug("cachedDevices size = " + cachedDevices.size());//更新藍(lán)牙列表UIfor (CachedBluetoothDevice cachedDevice : cachedDevices) {String name = cachedDevice.getDevice().getName();if (mA2dp != null && cachedDevice.getDevice() != null) {boolean a2dpPlaying = mA2dp.isA2dpPlaying(cachedDevice.getDevice());  //判斷藍(lán)牙是否使用中!if (a2dpPlaying) {LogUtil.debug("cachedDevices a2dpPlaying name = " + name);disconnectOtherExceptOne(name, cachedDevice.getDevice().getBluetoothClass().getMajorDeviceClass());}}}}}

LocalBluetoothManager 這個(gè)類(lèi)是SettingLib 里面的類(lèi),如果不是系統(tǒng)源碼或者系統(tǒng)應(yīng)用是調(diào)用不到的!可以用反射!

上面是實(shí)際項(xiàng)目中的一段代碼,其實(shí)具體獲取 BluetoothDevice api只有個(gè)兩句:

CachedBluetoothDevice cachedDevice;//單個(gè)藍(lán)牙對(duì)象
BluetoothDevice  bluetoothDevice = cachedDevice.getDevice();

四、其他:

     //已連接/綁定設(shè)備列表Set<BluetoothDevice> bondedDevices = mBluetoothManager.getBluetoothAdapter().getBondedDevices();

BluetoothDevice 對(duì)象沒(méi)有啥連接和斷開(kāi)操作的方法!只有一下配置信息。

http://www.risenshineclean.com/news/20.html

相關(guān)文章:

  • 福建建筑人才服務(wù)中心檔案/熱狗seo顧問(wèn)
  • 做網(wǎng)站困難嗎/優(yōu)秀網(wǎng)站設(shè)計(jì)欣賞
  • 做貨到付款的購(gòu)物網(wǎng)站/seo的中文含義是什么
  • 網(wǎng)站后臺(tái)是怎樣制作/經(jīng)典軟文案例100例簡(jiǎn)短
  • 2021年有沒(méi)有人給個(gè)網(wǎng)站/全網(wǎng)營(yíng)銷(xiāo)系統(tǒng)
  • 長(zhǎng)江設(shè)計(jì)公司/網(wǎng)絡(luò)優(yōu)化報(bào)告
  • 萬(wàn)網(wǎng)網(wǎng)站備案多久/免費(fèi)優(yōu)化網(wǎng)站
  • 上海網(wǎng)站排名優(yōu)化公司/谷歌seo快速排名軟件首頁(yè)
  • 網(wǎng)站建設(shè)開(kāi)發(fā)平臺(tái)/網(wǎng)絡(luò)服務(wù)器的作用
  • 做平面什么網(wǎng)站好用/百度禁止seo推廣
  • 中國(guó)平面設(shè)計(jì)網(wǎng)站/廣告營(yíng)銷(xiāo)案例分析
  • 網(wǎng)站建設(shè)橙子/百度教育app
  • 蘇省住房和城鄉(xiāng)建設(shè)廳網(wǎng)站首頁(yè)/百度應(yīng)用市場(chǎng)app下載安裝
  • 做網(wǎng)站需要源碼/河南做網(wǎng)站優(yōu)化