我正在开发一个“ 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”,这为我开发自己的“拨号程序”提供了解决方案,但我不想自己创建拨号程序。
答案 0 :(得分:0)
正像您怀疑的那样,有两种选择:
Call.disconnect()
API