以编程方式结束来电

Run*_*ion 24 android telephony telephonymanager

这是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

还有更多问题,答案和建议......

所有人都说ITelephonyService.aidlTelephonyManager结合使用

并且该解决方案在许多设备上都运行良好,但它不适用于Samsung S Duos.我挣扎了一个星期,但没有得到解决方案..是否有任何特殊的API可以在这种类型的设备上工作?我如何拒绝来电?请帮我...

Jeb*_*han 66

试试这个肯定会起作用.它对我来说很好.

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

之后,将方法添加到结束调用:

断开呼叫的功能

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); 
 }
}
Run Code Online (Sandbox Code Playgroud)

  • 太棒了,像魅力一样工作!你为我节省了很多时间,我很困惑为什么这篇文章的票数减少了 (2认同)
  • @Jeba:所以,我的问题是 - 它将断开连接的呼叫,唯一的来电或其他呼叫.因为,如果来电同时开始响铃,则另一个通话正在进行中.打电话给这会怎么样? (2认同)