gpt4 book ai didi

java - 如何在android JAVA中实现带有反射的隐藏接口(interface)?

转载 作者:行者123 更新时间:2023-11-30 04:24:00 25 4
gpt4 key购买 nike

我想稍后在 android 4.0 中使用 android.filterfw.* 框架。但是,它仍然隐藏在 SDK 中。
所以,现在我正在尝试 JAVA 反射技巧。

有谁知道如何在android JAVA中实现带有反射的隐藏接口(interface)?

我想用反射来模仿下面的代码。

private SurfaceTextureSourceListener mSourceReadyCallback = new SurfaceTextureSourceListener() {
public void onSurfaceTextureSourceReady(SurfaceTexture source) {

}
};

mGraphEnv.addReferences("textureSourceCallback", mSourceReadyCallback);

我做了这个。
Class c = Class.forName("android.filterpacks.videosrc.SurfaceTextureSource$SurfaceTextureSourceListener"); //step 1
instance = c.newInstance(); //step 2
proxy = Proxy.newProxyInstance(instance.getClass().getClassLoader(), new Class[] { instance.getClass() }, mHandler); //step 3

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

//TODO

return method.invoke(instance, args);
}
};

然后,我在“第 2 步”中遇到了异常。好的,我知道我无法创建接口(interface)目录的实例。
所以,我的问题是如何用反射实现隐藏接口(interface)。

我不能做这样的事情......
public class MyIPL implements SurfaceTextureSourceListener {

}

你知道任何想法吗?

最佳答案

阅读本文Hidden API

关于java - 如何在android JAVA中实现带有反射的隐藏接口(interface)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8830210/

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