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