以编程方式结束来电

这在SO中是一个熟悉的问题。 我需要的是以编程方式结束通话。 我搜查了很多…

http://androidsourcecode.blogspot.in/2010/10/blocking-incoming-call-android.html http://androiddesk.wordpress.com/2012/08/02/blocking-a-call-without-user-intervention -in-的Android /

在Android中拒绝来电

如何以编程方式在Android 4.1中接听/结束通话?

http://www.emoticode.net/android-sdk/block-incoming-and-outgoing-phone-calls-programmatically.html

如何在android中阻止呼叫

如何在Android应用程序开发中阻止手机号码和消息接收?

和http://androidsourcecode.blogspot.in/2010/10/blocking-incoming-call-android.html

还有更多的问题,答案和build议…

所有人都说使用ITelephonyService.aidl结合TelephonyManager

而且这个解决scheme在很多设备上都是非常完美的,但是在三星S Duos上却不能工作。 我挣扎了一个星期,但没有得到解决scheme..是否有任何特殊的API与这种types的设备上使用? 我怎样才能拒绝来电? 请帮帮我…

Solutions Collecting From Web of "以编程方式结束来电"

试试这个肯定会起作用。 这对我来说工作得很好。

您可以从ITelephony.java下载ITelephony.java文件

之后,您添加该方法结束通话:

断开呼叫的function

 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); } catch (Exception e) { e.printStackTrace(); Log.error(DialerActivity.this, "FATAL ERROR: could not connect to telephony subsystem"); Log.error(DialerActivity.this, "Exception object: " + e); } } 

试试这个function:

  private void endCall() { Context context = getApplicationContext(); try { TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); Class<?> c = Class.forName(telephony.getClass().getName()); Method m = c.getDeclaredMethod("getITelephony"); m.setAccessible(true); ITelephony telephonyService = (ITelephony) m.invoke(telephony); // Funciona en 2.2 // Funciona en 2.3.3 telephonyService.endCall(); logManager.debug("ITelepony was used (endCall)"); } catch (Exception e) { logManager.error("Error ending call: " + e.getMessage()); logManager.debug("Error ending call", e); } } 

在你的应用程序在java文件夹中创build一个包(com.android.internal.telephony)。 然后在该软件包中复制ITelephone界面

ITelephone界面来源: http ://grepcode.com/file_/repository.grepcode.com/java/ext/com.google.android/android/2.1_r2/com/android/internal/telephony/ITelephony.java/?v= 资源

代码断开呼叫:

 Context context = getApplicationContext(); try { TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); Class<?> c = Class.forName(telephony.getClass().getName()); Method m = c.getDeclaredMethod("getITelephony"); m.setAccessible(true); ITelephony telephonyService = (ITelephony) m.invoke(telephony); telephonyService.answerRingingCall(); } catch (Exception e) { } 

还要添加使用此方法的权限:

 <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.CALL_PHONE" /> <uses-permission android:name="android.permission.PROCESS_INCOMING_CALLS" />