如何在android JAVA中用反射实现隐藏界面?
我想在 android 4.0 以后使用 android.filterfw.* framworks 。但是,它仍然隐藏在SDK中。 所以,现在我正在尝试JAVA反射技巧。
有谁知道如何在android JAVA中用反射实现隐藏接口?
我想用反射来模仿下面的代码。
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步”上遇到了例外。好的,我知道我无法创建接口目录的实例。 所以,我的问题是如何用反射实现隐藏接口。
我不能做这样的事情...
public class MyIPL implements SurfaceTextureSourceListener {
}
你知道有什么想法吗?
I would like to use android.filterfw.* framworks in android 4.0 later. but, it is still hidden in SDK.
so, now I am trying JAVA reflection-tricks.
do anyone know how to implement hidden interface with reflection in android JAVA ?
I want to mimic the following code with reflection.
private SurfaceTextureSourceListener mSourceReadyCallback = new SurfaceTextureSourceListener() {
public void onSurfaceTextureSourceReady(SurfaceTexture source) {
}
};
mGraphEnv.addReferences("textureSourceCallback", mSourceReadyCallback);
I did this one.
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);
}
};
then, I got an exception on "step 2". OK, I understand I can't create an instance of interface directory.
so, my question is how to implement hidden interface with reflection.
I can not do something like this...
public class MyIPL implements SurfaceTextureSourceListener {
}
do you know any ideas ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论