android - 以编程方式结束来电

标签 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/

Rejecting Incoming call in android

How to programmatically answer/end a call in Android 4.1?

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

How to block calls in android

how to block a mobile number call and message receiving in android application development?

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

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

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

该解决方案在许多设备上都能完美运行,但在 Samsung S Duos 上却无法运行。我挣扎了一个多星期,但没有得到解决方案.. 在这种类型的设备上是否有任何特殊的 API 可以使用?如何拒接来电?请帮帮我...

最佳答案

试试这个 肯定会奏效的。它对我来说很好。

您可以从 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); 
 }
}

关于android - 以编程方式结束来电,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20965702/

相关文章:

ruby - IVR 的 Asterisk AGI 框架;粘附替代方案?

android - 如何触发react-native应用程序唤醒? (用于报警)

安卓实时通知

Android - 如何完全禁用键盘锁

android - 创建项目菜单中 API 集成的 Eclipse 插件和 ADT 修改

android - 如何以编程方式将调用屏幕置于最前面?

android - 如何从 android/internal/telephony/Phone.java 使用 getAvailableNetworks

android - 接听来电 Android Studio

android - 以编程方式在 Android 中获取我们的手机

android - TelephonyManager.getNetworkCountryIso() 究竟返回什么?