My goal is to display only contacts with a phone number for the user and allow the user to select multiple contacts that I want to save locally.
I used various options instead of ContactsContract.Contacts.CONTENT_URI below. But I get a lot of contacts (many of them are undesirable only with email identifiers).
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.contact_selector); ((Button)findViewById(R.id.btnphonecontactlist)).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) {
If I pass ContactsContract.Contacts.CONTENT_URI as a parameter to the method described above, and in the case of the method below, the String [] handler for the query method as projection parameters (which is commented out), the method does not work with java.lang. IllegalArgumentException. If I pass null in the method below, then no matter which contact I choose, I will not find a single column associated with a phone number or email.
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if(data != null) { Uri uri = data.getData(); if(uri != null) { Cursor c = null; try { c = getContentResolver().query(uri, null // new String[] { //ContactsContract.CommonDataKinds.Phone.NUMBER, //ContactsContract.CommonDataKinds.Phone.TYPE}, , null, null, null); if(c != null && c.moveToFirst()) { String number = c.getString(0); String type = c.getString(1); } } finally { if(c != null && !c.isClosed()) c.close(); } } } }
Is there a way to display only the contacts visible to the user, usually when the user goes to the phone book and has phone numbers?
I tried to go through all the threads in stackoverflow and other sites, but could not find a solution that solves the problem around this, although many people posted this problem. I didn’t work very much with the Android platform, and maybe I missed some small details, and I believe that this requires an easy way.
Please offer. Appreciate your help.
Thanks.