2

How to make a missed call from android app to a specified number. I have tried this but it would start a call and will wait for the call to terminate. I want the call to ring once and then stop. Please help me.

Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:123456789"));
startActivity(callIntent);
Nikhil Baby
  • 863
  • 3
  • 10
  • 22
  • I don't think it's possible because phone call is made by the system which you don't have control of unless rooted, you can hang up before the call is started (http://stackoverflow.com/questions/599443/how-to-hang-up-outgoing-call-in-android), but not in the middle of the call – WenChao Jan 12 '17 at 04:36

1 Answers1

0

make a missed call from android app to a specified number

You can achieve it but not guaranteed (if other person receives the call instantly)! Do your calculation how much time it takes for 1 ring. Start a Thread/Timer and then Call this method to end the call!

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");

    }
}
Sadiq Md Asif
  • 882
  • 6
  • 18