[英]How to End Incoming Call in Monodroid?
Java開發人員一直使用反射直到2.3才到達ITelephony的endcall方法,以結束傳入呼叫,但是此方法后來被阻止,因此也無法通過c#訪問monodroid。
在“ Mono For Android”中有什么方法可以做到嗎?
Java開發人員已使用反射
這是完全一樣的:您將使用JNIEnv而不是Java反射。
假設您要移植此基於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());
}
如果斜視正確 ,可以得到以下代碼(完全未經測試!)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.