我正在开发一个“DemoApp”,在其中我做了一个“结束通话”按钮,当我的手机有任何来电时,我只是使用默认拨号应用程序收到它,然后我打开我的“DemoApp”,当我按下“结束通话”按钮,我只想结束来电。
我已经通过以下代码成功完成了“结束通话”功能:
private boolean declinePhone() {
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);
return true;
} catch (Exception e) {
e.printStackTrace();
Log.d("unable", "msg cant dissconect call....");
}
return false;
}
我只想知道我是否可以通过使用“ConnectionService”API 来实现这一点。我研究了“ https://developer.android.com/guide/topics/connectivity/telecom/selfManaged ”这篇文章,它为我提供了开发自己的“拨号器应用程序”的解决方案,但我不想自己制作拨号器。