1

I am initiating a phone call from an activity and would like to close the dialer automatically after 7 seconds (and end the phone call).

This code doesn't work:

private static final int REQUEST_CALL = 135;
private long nCallShouldEndAfterMs = 7 * 1000;

private void callNumber()
{
    Intent callIntent = new Intent(Intent.ACTION_CALL);
    callIntent.setData(Uri.parse("tel:" + sMyNum));
    startActivityForResult(callIntent, REQUEST_CALL);

    scheduleClosingDialer();
}


private void scheduleClosingDialer()
{
    handler.postDelayed(new Runnable()
    {           
        @Override
        public void run()
        {
            try
            {
                Log.d(TAG, "closing dialer");
                finishActivity(REQUEST_CALL);
            }
            catch(Exception e)
            {
                Log.w(TAG, "Dialer already closed");
            }               
        }
    }, nCallShouldEndAfterMs);
}
A.G.
  • 2,037
  • 4
  • 29
  • 40
  • Try this one http://stackoverflow.com/questions/18065144/end-call-in-android-programatically , may be help you out too. Also http://stackoverflow.com/questions/13230512/how-to-disconnect-the-call-in-android-4-1-2-nexus-programmatically – bobby.dhillon Jan 15 '14 at 17:08
  • You'll have to do it from a Service, because while calling your activity won't be on top. – pozuelog Jan 15 '14 at 17:12

0 Answers0