gpt4 book ai didi

java - 隐藏界面的反射

转载 作者:行者123 更新时间:2023-12-02 12:45:06 36 4
gpt4 key购买 nike

如何调用registerAudioPortUpdateListener
我成功调用了隐藏函数。
但是,在这种情况下,我需要调用一个以隐藏内部接口(interface)作为参数的函数。

public class AudioManager {
/**
* Listener registered by client to be notified upon new audio port connections,
* disconnections or attributes update.
* @hide
*/
public interface OnAudioPortUpdateListener {
/**
* Callback method called upon audio port list update.
* @param portList the updated list of audio ports
*/
public void onAudioPortListUpdate(AudioPort[] portList);

/**
* Callback method called upon audio patch list update.
* @param patchList the updated list of audio patches
*/
public void onAudioPatchListUpdate(AudioPatch[] patchList);

/**
* Callback method called when the mediaserver dies
*/
public void onServiceDied();
}


/**
* Register an audio port list update listener.
* @hide
*/
public void registerAudioPortUpdateListener(OnAudioPortUpdateListener l) {
sAudioPortEventHandler.init();
sAudioPortEventHandler.registerListener(l);
}
}

最佳答案

你能试试这个代码吗,对我来说它在java中工作,

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

import de.apps.io.AudioManager;


public class Application {

public static void main(String[] args) {
System.out.println("hello world");



Class someInterface1 = null;
try {
// someInterface = AudioManager.class.getDeclaredClasses();

someInterface1 = Class.forName("de.apps.io.AudioManager$OnAudioPortUpdateListener");
} catch (Exception e) {
e.printStackTrace();
}

//System.out.println(someInterface);


System.out.println(someInterface1);



Object o = Proxy.newProxyInstance(someInterface1.getClassLoader(), new java.lang.Class[] { someInterface1 }, new Handler());


AudioManager manager = new AudioManager();
Method me = null;
try {
me = manager.getClass().getMethod("registerAudioPortUpdateListener", new java.lang.Class[] { someInterface1 });
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
me.invoke(manager, o);
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(me);

}



static class Handler implements InvocationHandler
{

@Override
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {

String method_name = method.getName();
Class<?>[] classes = method.getParameterTypes();

System.out.println("called " + method_name);

return null;
}

}

}

关于java - 隐藏界面的反射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44800246/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com