1

So, I have a list of phone contacts that I need to call in order from my app. I call the first number, wait for it to end, then call the next one, wait and so on.

How do I modify my code so that the next contact is called only if the current call is ended unanswered(Missed call)?

As of now my code looks like this.

On click listener for the Button:

callButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Realm db = Realm.getDefaultInstance();
                RealmQuery<Contact> query = db.where(Contact.class);
                RealmResults<Contact> results= query.findAll();
                callAllContacts(results);
            }
        });

callAllContacts(RealmResults):

private void callAllContacts(RealmResults<Contact> results){
        for(Contact c: results){
            Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+c.getPhone()));
            if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CALL_PHONE)
                    == PackageManager.PERMISSION_GRANTED) {
                Toast.makeText(MainActivity.this,"Calling " + c.getName(),Toast.LENGTH_SHORT).show();
                startActivity(intent);
            }
        }
    }

Contact.java:

public class Contact extends RealmObject{

    public Contact() {
        name = "";
        phone = "";
    }

    @NonNull
    public String name;

    @PrimaryKey
    public String phone;

    @NonNull
    public String getName() {
        return name;
    }

    public void setName(@NonNull String name) {
        this.name = name;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }
}

0 Answers0