Java Android BluetoothService类的反射问题

Java Android BluetoothService类的反射问题,java,android,reflection,bluetooth,Java,Android,Reflection,Bluetooth,我想调用BluetoothService类的一些方法,如isEnabled()、getAddressFromObjectPath()等,但是这个类是用@hide标记的 我知道我有两种可能的方法来做我想做的事情,一种是删除@hide,另一种是使用反射。我选择使用第二个 从源代码示例中,我发现 Method method = Class.forName("android.os.ServiceManager").getMethod("getService", String.class);

我想调用BluetoothService类的一些方法,如isEnabled()、getAddressFromObjectPath()等,但是这个类是用@hide标记的

我知道我有两种可能的方法来做我想做的事情,一种是删除@hide,另一种是使用反射。我选择使用第二个

从源代码示例中,我发现

    Method method = Class.forName("android.os.ServiceManager").getMethod("getService", String.class);
    IBinder b = (IBinder) method.invoke(null, "bluetooth");

    if (b == null) {
        throw new RuntimeException("Bluetooth service not available");
    }

    IBluetooth mBluetoothService = IBluetooth.Stub.asInterface(b);
然而,它得到的是IBluetooth而不是Bluetooth服务,尽管Bluetooth服务确实扩展了IBluetooth.Stub

因此,我的问题如下:

(1) 我可以像前面的示例代码一样通过反射获得BluetoothService类吗? (2) 如果我的第一个问题是否定的,我将通过反射方法直接调用getAddressFromObjectPath(),如下所示

    Method method = Class.forName("android.server.BluetoothService").getMethod("getAddressFromObjectPath", String.class);
    String b = (String) method.invoke(???, PATH);
我需要在invoke()方法中填充什么对象,BluetoothService


任何建议都将不胜感激

在网上调查后,我得到了答案。如果我想调用一个非静态方法,我需要首先获取类和构造函数。使用构造函数构造实例,然后我可以通过该实例调用非静态方法。 然而,我不能在BluetoothService类上这样做,因为如果我再做一次构造函数,它将导致很多问题! 我决定修改IBluetooth.aidl以添加所需的方法,因为BluetoothService扩展了IBluetooth。如果我能得到IBluetooth实例,我就可以调用我需要的方法。也许,这不是一个好的解决方案,但我认为它会起作用

非常感谢