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

當前位置: 首頁 > news >正文

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

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

#Android9 查看連接多個藍牙耳機查看使用中的藍牙耳機

文章目錄

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

Android 9.0之后,支持一臺手機可以同時連接多個藍牙設備。

但是判斷那個藍牙設備是使用中,需要經(jīng)過一些復雜判斷才知道!

一、主要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中回調(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)換 ,這個就是  BluetoothA2dp 對象//不顯示藍牙界面連接耳機會出現(xiàn)多個連接狀態(tài)的藍牙耳機,斷開非使用中的藍牙耳機judgeIsConnectManyBluetooth();}}};

三、獲取 BluetoothDevice 對象,

	//判斷所有的耳機設備是否存在多個連接狀態(tài)的private boolean isConnectManyBluetooth() {//未從已連接設備列表中找到斷開的api,從所有的設備列表中進行判斷連接狀態(tài)后斷開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;}//判斷是否多個藍牙連接狀態(tài),如果是就斷開非使用中的藍牙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 里面的類,如果不是系統(tǒng)源碼或者系統(tǒng)應用是調(diào)用不到的!可以用反射!

上面是實際項目中的一段代碼,其實具體獲取 BluetoothDevice api只有個兩句:

CachedBluetoothDevice cachedDevice;//單個藍牙對象
BluetoothDevice  bluetoothDevice = cachedDevice.getDevice();

四、其他:

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

BluetoothDevice 對象沒有啥連接和斷開操作的方法!只有一下配置信息。

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

相關文章:

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