1

I am trying to make multiple phone calls via my android app one after another, by calling a function inside a loop and providing a phone number as a parameter, then the call is made and the function ends and returns to the loop for next phone call and the function with next number is called.

I have tried adding wait() for a certain time which makes the app run as intended, but if call duration is bigger than wait time it doesn't work.

private void callingStart() { while (tempAL.size() > 0) {

            PhoneNumber = (String) tempAL.get(0);
            PhoneNumber.trim();
            tempAL.remove(callingIndex);
            if (PhoneNumber.length() > 0) {
                finish();
                makePhoneCall(PhoneNumber);                                
            } 
        }

}

private void makePhoneCall(String PhoneNumber1) {

    if (ContextCompat.checkSelfPermission(callresult.this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {

        ActivityCompat.requestPermissions(callresult.this, new String[]{Manifest.permission.CALL_PHONE}, REQUEST_CALL);

    } 
    else {

            if (COUNT == callMade) {
                startActivity(getIntent());
                String dial = "tel:" + PhoneNumber1;
                Intent i = new Intent(Intent.ACTION_CALL, Uri.parse(dial));
                startActivity(i);
            }            
    }
}

I was expecting that call would be made one by one. But all the calls are made at once or only the last call is made.

I want to make phone call only after the previous call ends. How can I do that?

Zoe
  • 27,060
  • 21
  • 118
  • 148
aditya
  • 123
  • 2
  • 11

1 Answers1

0

You don't wait for the phone call to finish- you'd register for notification of phone events. I have some old code at How to detect incoming calls, in an Android device? which will show how to know when a call is ended. When it ends, then you unregister and run whatever code you would have waited for.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
  • I am new to Android programming, can you please explain in detail what I've to do to make it work. – aditya Jun 02 '19 at 07:47