Search code examples
androidphone-call

How to detect that the call which is done from our android device is answered or rejceted?


I am making an application to call multiple numbers.

In that app

  1. When I call to 1 person and if the call is answered by the user then the loop should be stopped.

  2. But If the call is rejected then the call should be on next number and loop should be couninue.

My problem is I cant detect whether the call is rejected or answered. when I had search on net some people says it is not possible to detect the call is answered or rejected.

Is it really not possible to detect the call in android If it is possible then how can I do that?


Solution

  • I think you can check outgoing call time of last call in PhoneStateListener class' onCallStateChanged method. Fetch the data if state is idle that is TelephonyManager.CALL_STATE_IDLE.

    Something like this:

    Cursor mCallCursor = context.getContentResolver().query(android.provider.CallLog.Calls.CONTENT_URI,null,null,null,null);
    int duration = mCallCursor.getColumnIndex( CallLog.Calls.DURATION);
    while(mCallCursor.moveToFirst())
    {   
        Toast.makeText(context, mCallCursor.getString(duration), Toast.LENGTH_LONG).show();
    }
    

    You can find more about that here. I haven't tested the above code. But something like that should work.

    You can check if time's 00:00, then call next number of loop. Else you can stop calling.

    Hope this helps you.