简体   繁体   中英

How to avoid complete action using dialog to read a contact or to do a call phone

In my app i have a button to select a contact from contacts phone and a button to start a call phone to this number. So when i click on the button to select the contact, the complete action using dialog appears with more apps to choose as well as when i click on the button to star the call phone. How can i avoid the dialog to access contacts and to do a call phone directly?

Partial code of my activity:

contacts.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(Intent.ACTION_PICK,  ContactsContract.Contacts.CONTENT_URI);
            startActivityForResult(intent, 0);
        }
});

start.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {   
String numeroDiTelefono = dati.getString("numeroDiTelefono");
    Intent callIntent = new Intent(Intent.ACTION_CALL);
    callIntent.setData(Uri.parse("tel:" + numeroDiTelefono));
    callIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(callIntent);
        }
});

Make sure you have added the permission in the Manifest file:

<uses-permission android:name="android.permission.CALL_PHONE" />

And all you should need for the Intent is:

Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+numeroDiTelefono));
startActivity(callIntent);

Basically that dialog means you have more than one contacts app installed on your phone. This is a default Android system behavior when you call any kind of common intent actions.

What you can do is make the intent more specific to the app you're looking for. By specifing a) the specific data uri b) the package name c) set the content type, etc

Also try this.

Intent i = new Intent(Intent.ACTION_PICK, ContactsContract.CommonDataKinds.Phone.CONTENT_URI);
startActivityForResult(i, PICK_CONTACT);
public void onClick(View view) {
            String number = String.valueOf(bundle.getLong("phone"));
            Uri call = Uri.parse("tel:" + number);
            Intent intent = new Intent(Intent.ACTION_DIAL, call);
            startActivity(intent);
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM