gpt4 book ai didi

android - 无法在 oreo -telephony manager 中结束通话

转载 作者:太空狗 更新时间:2023-10-29 13:50:37 26 4
gpt4 key购买 nike

我希望在触摸按钮时自动拒绝来电。为此,我曾经收到一个 PhoneStateListener 回调,其中我正在获取手机号码并使用电话管理器我能够结束调用棉花糖版本..

当我构建 apk 并尝试在 oreo 中执行时,它失败了。我接到电话,但没有自动拒接电话。

这是结束通话的尝试代码。

  public void disconnectCall() {
try {
String serviceManagerName = "android.os.ServiceManager";
String serviceManagerNativeName = "android.os.ServiceManagerNative";
String telephonyName = "com.android.internal.telephony.ITelephony";
Class<?> telephonyClass;
Class<?> telephonyStubClass;
Class<?> serviceManagerClass;
Class<?> serviceManagerNativeClass;
Method telephonyEndCall;
Object telephonyObject;
Object serviceManagerObject;
telephonyClass = Class.forName(telephonyName);
telephonyStubClass = telephonyClass.getClasses()[0];
serviceManagerClass = Class.forName(serviceManagerName);
serviceManagerNativeClass = Class.forName(serviceManagerNativeName);
Method getService = // getDefaults[29];
serviceManagerClass.getMethod("getService", String.class);
Method tempInterfaceMethod = serviceManagerNativeClass.getMethod("asInterface", IBinder.class);
Binder tmpBinder = new Binder();
tmpBinder.attachInterface(null, "fake");
serviceManagerObject = tempInterfaceMethod.invoke(null, tmpBinder);
IBinder retbinder = (IBinder) getService.invoke(serviceManagerObject, "phone");
Method serviceMethod = telephonyStubClass.getMethod("asInterface", IBinder.class);
telephonyObject = serviceMethod.invoke(null, retbinder);
telephonyEndCall = telephonyClass.getMethod("endCall");
telephonyEndCall.invoke(telephonyObject);

最佳答案

试试这个,

您不需要成为系统应用程序。首先,创建包 com.internal.android.telephony在您的项目中,并将其放入名为“ITelephony.aidl”的文件中:

首先制作处理手机状态的界面,就像我制作的一样。

interface ITelephony {      

boolean endCall();

void answerRingingCall();

void silenceRinger();

}

一旦你有了它,你就可以使用这个代码来结束通话:

TelephonyManager telephonyManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
Class clazz = Class.forName(telephonyManager.getClass().getName());
Method method = clazz.getDeclaredMethod("getITelephony");
method.setAccessible(true);
ITelephony telephonyService = (ITelephony) method.invoke(telephonyManager);
telephonyService.endCall();

注意:要使其正常工作,您需要在 list 中定义所需的权限:

<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 -telephony manager 中结束通话,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48071679/

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