我正在使用下面的代码结束通话。但现在在 Oreo 上,我收到一个错误,指出需要 MODIFY_PHONE_STATE
权限,因此此代码不再有效。
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
// Toast.makeText(context, "here", Toast.LENGTH_LONG).show();
assert telephonyManager != null;
Class clazz = Class.forName(telephonyManager.getClass().getName());
Method method = clazz.getDeclaredMethod("getITelephony");
method.setAccessible(true);
ITelephony telephonyService;
telephonyService = (ITelephony) method.invoke(telephonyManager);
telephonyService.silenceRinger();
telephonyService.endCall();
此外,根据文档和许多博客,MODIFY_PHONE_STATE
权限仅对系统应用程序有效。
那么现在我们将如何结束通话?
有没有别的办法。
错误:
java.lang.SecurityException: MODIFY_PHONE_STATE permission required.
at android.os.Parcel.readException(Parcel.java:2004)
at android.os.Parcel.readException(Parcel.java:1950)
W/System.err: at com.android.internal.telephony.ITelephony$Stub$Proxy.endCall(ITelephony.java:2025)
最佳答案
Google 对应用程序可以做什么和不能做什么施加了很多限制。即使你设法找到一些内部实现并通过反射调用,它也无助于 Anddoid P 具有阻止这些尝试的增强机制。
唯一的出路是构建您自己的通话应用程序,这将使您能够完全控制通话管理。可以关注这个official document其中描述了构建应用程序的过程
关于java - TelephonyManager 结束通话的替代方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50653945/