在Oreo中以编程方式杀死电话 [英] Kill a phone call programatically in Oreo
本文介绍了在Oreo中以编程方式杀死电话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用此方法结束android中的呼叫
I am using this method to end a call in android
public boolean killCall(Context context) {
try {
// Get the boring old TelephonyManager
TelephonyManager telephonyManager =
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
// Get the getITelephony() method
Class classTelephony = Class.forName(telephonyManager.getClass().getName());
Method methodGetITelephony = classTelephony.getDeclaredMethod("getITelephony");
// Ignore that the method is supposed to be private
methodGetITelephony.setAccessible(true);
// Invoke getITelephony() to get the ITelephony interface
Object telephonyInterface = methodGetITelephony.invoke(telephonyManager);
// Get the endCall method from ITelephony
Class telephonyInterfaceClass =
Class.forName(telephonyInterface.getClass().getName());
Method methodEndCall = telephonyInterfaceClass.getDeclaredMethod("endCall");
// Invoke endCall()
methodEndCall.invoke(telephonyInterface);
} catch (Exception ex) { // Many things can go wrong with reflection calls
Log.d(TAG, "PhoneStateReceiver **" + ex.getCause().getStackTrace());
return false;
}
return true;
}
这在Oreo之前有效,但在android oreo上无效,这是什么意思
This does work before Oreo but does not working on android oreo any idea what is missing.
最好的问候:阿里
推荐答案
我做你的代码并按照说明进行操作:
以编程方式在android中结束通话
I do your code and follow the explain: End call in android programmatically
添加以下权限
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
然后运行良好,我的代码在android oreo版本上运行。
then it's working very well, my code is running on android oreo version.
这篇关于在Oreo中以编程方式杀死电话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文