Android 如何在 android.telecom.Call 类中反射 [英] Android how do to reflection in android.telecom.Call class
本文介绍了Android 如何在 android.telecom.Call 类中反射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想阻止一个电话,我尝试使用带有以下代码的反射 android.telecom.Call 类,但该类没有构造函数.
I want to block a phone call and i try using reflection android.telecom.Call class with following code but this class does not has constructor .
try {
Class c = Class.forName("android.telecom.Call");
Method m = c.getMethod("disconnect");
m.setAccessible(true);
Object o = m.invoke(c, new Object[] {});
} catch (Exception e) {
Log.e("Exception of Reflection", e.getLocalizedMessage());
}
推荐答案
- 您需要实例化类调用,因为您将使用该实例作为您的目标 方法调用.
- 方法 getMethod 忽略非公共方法.您应该使用 getDeclaredMethod 找到您的私有方法.
- You need to instantiate Class Call because you'll use the instance as a target for you method invocation.
- The method getMethod ignores non-public method. You should use getDeclaredMethod to find your private method.
您的代码可能如下所示:
Your code may look like this:
try
{
Class<?> c = Class.forName("android.telecom.Call");
Object instance = c.newInstance();
Method m = c.getDeclaredMethod("disconnect");
m.setAccessible(true);
m.invoke(instance, new Object[] {});
}
catch (Exception e)
{
Log.e("Exception of Reflection", e.getLocalizedMessage());
}
这篇关于Android 如何在 android.telecom.Call 类中反射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文