Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intent for contacts with phone number

Please, is it possible to pick from contacts only with phone number/s using intent and default contacts app?

Maybe some modification of this (shows selection from all contacts):

Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(intent, CONTACT_PICKER_ID);
like image 262
Perry_ml Avatar asked Aug 23 '12 20:08

Perry_ml


People also ask

How do you call an intent?

Intent Object - Action to make Phone CallIntent phoneIntent = new Intent(Intent. ACTION_CALL); You can use ACTION_DIAL action instead of ACTION_CALL, in that case you will have option to modify hardcoded phone number before making a call instead of making a direct call.

How do I select and display my phone number from a contact list on Android?

Open your Contacts app and tap the Options button (three dots), and select Contacts Manager. On the next screen, tap on Contacts to display from the menu. Next, if you only want contacts with a phone number, tap on Phone.

What is ContactsContract?

* ContactsContract defines an extensible database of contact-related. * information. Contact information is stored in a three-tier data model: * </p>


2 Answers

Intent intent = new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI);
intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
startActivityForResult(intent, 1);
like image 125
AlBeebe Avatar answered Sep 28 '22 09:09

AlBeebe


You can open a cursor on the contacts and run through getting the contacts with phone numbers. You could recreate the contact picker activity that is shown from the intent you mentioned using this cursor (throwing them into a listview to pick from)

        ContentResolver cr = getContentResolver();
        Cursor phoneCur = cr.query( 
                ContactsContract.CommonDataKinds.Phone.CONTENT_URI, 
                null,
                null, 
                null, 
                null); 
        while (phoneCur.moveToNext()) { 
            String phone = phoneCur.getString(
                      phoneCur.getColumnIndex(
                              ContactsContract.CommonDataKinds.Phone.DATA));
            //do something, check if empty...
        } 
        phoneCur.close();

with this approach you will also need the read contact permission in you manifest

<uses-permission android:name="android.permission.READ_CONTACTS"/>
like image 25
Patrick Kafka Avatar answered Sep 28 '22 10:09

Patrick Kafka