【问题标题】:Missed call in background in androidAndroid后台未接来电
【发布时间】:2017-05-27 02:06:15
【问题描述】:

如何将未接电话从 android 应用程序拨打到指定号码。我已经尝试过了,但它会开始通话并等待通话终止。我希望电话响一次然后停止。请帮帮我。

Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:123456789"));
startActivity(callIntent);

【问题讨论】:

  • 我不认为这是可能的,因为电话是由你无法控制的系统拨打的,除非root,你可以在通话开始之前挂断(stackoverflow.com/questions/599443/…),但是不在通话中

标签: android performance background call


【解决方案1】:

从安卓应用打一个未接电话到指定号码

您可以实现但不能保证(如果其他人立即接到电话)!计算一下 1 次响铃需要多少时间。启动一个Thread/Timer 然后调用这个方法结束通话!

private void mEndCall() {
        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 serviceManagerStubClass;
        Class serviceManagerNativeClass;
        Class serviceManagerNativeStubClass;

        Method telephonyCall;
        Method telephonyEndCall;
        Method telephonyAnswerCall;
        Method getDefault;

        Method[] temps;
        Constructor[] serviceManagerConstructor;

        // Method getService;
        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);
        //telephonyCall = telephonyClass.getMethod("call", String.class);
        telephonyEndCall = telephonyClass.getMethod("endCall");
        //telephonyAnswerCall = telephonyClass.getMethod("answerRingingCall");

        telephonyEndCall.invoke(telephonyObject);

    } catch (Exception e) {
        e.printStackTrace();
        Log.e("error",
                "FATAL ERROR: could not connect to telephony subsystem");

    }
}

【讨论】:

  • 这不是一个可靠的方法,因为通话时间变化很大。谢谢你的回答。
猜你喜欢
  • 2016-03-09
  • 2014-06-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多