i want to fetch users contacts through my android application and i also give permission in Manifests file in android i can't know how can i see them contacts please help me
Asked
Active
Viewed 63 times
-1
-
Did you try to search for this? Dont tell SO that you are not able to find any help! – Sreehari Jun 18 '16 at 07:47
-
1Possible duplicate of http://stackoverflow.com/questions/4133163/how-to-get-phone-contacts-in-android – Anjali Jun 18 '16 at 07:49
2 Answers
0
You can try below Snippet :
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,null, null, null, null);
if (cur.getCount() > 0) {
while (cur.moveToNext()) {
String id = cur.getString(
cur.getColumnIndex(ContactsContract.Contacts._ID));
String name = cur.getString(
cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
if (Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
//Query phone here. Covered next
}
}
}

DeepThinker
- 88
- 9
0
package com.example.harismahmood.fhfountainhouse;
import android.app.Activity;
import android.app.ListActivity;
import android.database.Cursor;
import android.provider.ContactsContract;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
public class ContactListview extends ListActivity {
@Override
public int getSelectedItemPosition() {
return super.getSelectedItemPosition();
}
@Override
public long getSelectedItemId() {
return super.getSelectedItemId();
}
ListView lv;
Cursor cursor1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_contact_listview);
cursor1 = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI ,null, null, null, null);
startManagingCursor(cursor1);
String[] from = {ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.CommonDataKinds.Phone._ID};
int[] to = {android.R.id.text1 , android.R.id.text2};
SimpleCursorAdapter listadapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_2, cursor1,from,to);
setListAdapter(listadapter);
lv = getListView();
lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
}
}

haris mahmood
- 9
- 7