Android开源项目.disconnect方法&BluetoothHeadsetClient类隐藏的任何解决方法
创始人
2024-10-08 16:33:43
0

在Android 10及以上版本中,Android Open Source项目中的.disconnect方法和BluetoothHeadsetClient类都被隐藏了,这个问题可以通过使用Java的反射机制来解决。以下是一个代码示例:

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;

public class MyBluetoothProfile implements BluetoothProfile {
   private BluetoothHeadset mService;
   private Method disconnectMethod;

   public MyBluetoothProfile(BluetoothHeadset service) {
       mService = service;
       try {
           disconnectMethod = mService.getClass().getMethod("disconnect",
              BluetoothDevice.class);
       } catch (NoSuchMethodException ex) {
           ex.printStackTrace();
           disconnectMethod = null;
       }
   }

   // This method is hidden in Android 10, so we use reflection to call it
   public boolean disconnect(BluetoothDevice device) {
       if (disconnectMethod != null) {
           try {
               return (Boolean)disconnectMethod.invoke(mService, device);
           } catch (IllegalAccessException ex) {
               ex.printStackTrace();
           } catch (InvocationTargetException ex) {
               ex.printStackTrace();
           }
       }
       return false;
   }

   // Rest of the BluetoothProfile implementation goes here...
}

相关内容

热门资讯

连日来!哈糖大菠萝破解器(透视... 连日来!哈糖大菠萝破解器(透视)微信小程序哥哥打大a辅助(真是有辅助神器)-哔哩哔哩1、每一步都需要...
透视存在!pokemmo手机版... 透视存在!pokemmo手机版脚本免费(透视)西部透视辅助(好像存在有辅助app)-哔哩哔哩1、玩家...
透视新版!拱趴大菠萝怎么开挂(... 透视新版!拱趴大菠萝怎么开挂(透视)三哥玩辅助器软件(好像存在有辅助软件)-哔哩哔哩1、三哥玩辅助器...
据目击者称!wepoker怎么... 据目击者称!wepoker怎么设置透视(透视)创思维激k辅助插件(一贯有辅助插件)-哔哩哔哩一、创思...
透视游戏!wepoker正确养... 透视游戏!wepoker正确养号方法(透视)甘肃白银麻将辅助软件(切实是真的辅助修改器)-哔哩哔哩;...
事发当天!wejoker辅助软... 事发当天!wejoker辅助软件视频(透视)皇豪互众智能辅助器(原来真的是有辅助平台)-哔哩哔哩1、...
经核实!wepoker看底牌(... 经核实!wepoker看底牌(透视)新天道怎么看底牌(果然真的是有辅助插件)-哔哩哔哩1、新天道怎么...
有玩家发现!wepokerpl... 有玩家发现!wepokerplus到底是挂了吗(透视)丽水茶苑脚本(原来真的有辅助插件)-哔哩哔哩1...
透视好牌!wepoker辅助器... 透视好牌!wepoker辅助器安装包定制(透视)潘潘讲故事辅助器(好像真的有辅助辅助器)-哔哩哔哩1...
透视挂!wepoker是不是有... 透视挂!wepoker是不是有人用挂(透视)宝宝斗场辅助器(竟然是真的辅助神器)-哔哩哔哩暗藏猫腻,...