Search code examples
androidphone-calltelephonytelephonymanager

How to check if the dialed number is busy or is not answered?


I have used the following code to dial a number:

DataBaseHelper db;
db=new DataBaseHelper(PanicService.this);
try {

    db.createDataBase();

    } catch (IOException ioe) {

    throw new Error("Unable to create database");

    }

Map<String, String > map= db.TelephoneList();
String[] numbers = new String[]{"number1","number2","number3","number4","number5"};


Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+map.get(numbers[0])));
callIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(callIntent);

which is working fine. Now I need to know if the dialled number is busy or is unanswered, and it it is dial the next number in the list. I am just wondering if there is anyway to detect the state of the call?

I have checked this URL http://developer.android.com/reference/android/telephony/TelephonyManager.html but I can't find anything around that concept apart from CALL_STATE_OFFHOOK which is not really what I want.


Solution

  • You cannot determine whether an outgoing call on the mobile network was answered, because this information isn't provided to the handset by the mobile network, and even if it was, Android does not provide a way to receive it.

    While it's possible to determine whether an outgoing Internet (SIP) call was answered, Android doesn't currently (as of Jelly Bean) provide a way of doing this that I can find from a quick look at the source code.