简体   繁体   English

如何结束Monodroid的来电?

[英]How to End Incoming Call in Monodroid?

Java developers had used reflection for reaching endcall method of ITelephony until 2.3, in order to end incoming call, but this method has been prevented later, so it is nonaccessible via c# in monodroid neither. Java开发人员一直使用反射直到2.3才到达ITelephony的endcall方法,以结束传入呼叫,但是此方法后来被阻止,因此也无法通过c#访问monodroid。

Is there any way to do it in 'Mono For Android'? 在“ Mono For Android”中有什么方法可以做到吗?

Java developers had used reflection Java开发人员已使用反射

It's the-same-just-different: instead of Java reflection, you'd use JNIEnv . 这是完全一样的:您将使用JNIEnv而不是Java反射。

Assume you want to port this Java reflection-based code : 假设您要移植此基于Java反射的代码

try {
    TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    Class c = Class.forName(manager.getClass().getName());
    Method m = c.getDeclaredMethod("getITelephony");
    m.setAccessible(true);
    ITelephony telephony = (ITelephony)m.invoke(manager);
    telephony.endCall();
} catch(Exception e){
    Log.d("",e.getMessage());
}

If you squint just right , you can get this (entirely untested!) C# code: 如果斜视正确 ,可以得到以下代码(完全未经测试!)C#代码:

var manager = (TelephonyManager) this.GetSystemService (Context.TelephonyService); 

IntPtr TelephonyManager_getITelephony = JNIEnv.GetMethodID (
        manager.Class.Handle,
        "getITelephony",
        "()Lcom/android/internal/telephony/ITelephony;");

IntPtr telephony          = JNIEnv.CallObjectMethod (manager.Handle, TelephonyManager_getITelephony);
IntPtr ITelephony_class   = JNIEnv.GetObjectClass (telephony);
IntPtr ITelephony_endCall = JNIEnv.GetMethodID (
        ITelephony_class,
        "endCall",
        "()Z");
JNIEnv.CallBooleanMethod (telephony, ITelephony_endCall);
JNIEnv.DeleteLocalRef (telephony);
JNIEnv.DeleteLocalRef (ITelephony_class);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM