gpt4 book ai didi

c# - 如何在 Monodroid 中结束来电?

转载 作者:太空宇宙 更新时间:2023-11-03 18:34:23 25 4
gpt4 key购买 nike

Java 开发人员在 2.3 之前一直使用反射到达 ITelephony 的 endcall 方法,以结束来电,但此方法后来被阻止,因此在 monodroid 中也无法通过 c# 访问它。

在“Mono For Android”中有什么方法可以实现吗?

最佳答案

Java developers had used reflection

相同只是不同:您可以使用 JNIEnv 而不是 Java 反射.

假设您要移植此 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());
}

如果你斜视恰到好处,你可以得到这个(完全未经测试!)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);

关于c# - 如何在 Monodroid 中结束来电?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17427174/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com