简体   繁体   中英

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.

Is there any way to do it in 'Mono For Android'?

Java developers had used reflection

It's the-same-just-different: instead of Java reflection, you'd use JNIEnv .

Assume you want to port this Java reflection-based code :

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:

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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