public class ImportContactsActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button pickContact = (Button) findViewById(R.id.contacts);
pickContact.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(intent, 1);
}
});
}
public void onActivityResult(int reqCode, int resultCode, Intent data) {
super.onActivityResult(reqCode, resultCode, data);
switch (reqCode) {
case (1) :
if (resultCode == Activity.RESULT_OK) {
Uri contactData = data.getData();
Cursor c = managedQuery(contactData, null, null, null, null);
if (c.moveToFirst()) {
String name = c.getString(c.getColumnIndexOrThrow(People.NAME));
TextView contactView = (TextView) findViewById(R.id.contactView);
contactView.setText(name.toString());
}
}
break;
}
}
I am developing an Android apps and I am importing the phone contacts into my apps, after user clicks on the selected contact, the contact will be shown in a TextView and the phone number will be stored in the sharedpreferences... May I know how to achieve it? Thanks
Have you tried?
For store in
SharedPreferences
..The above code is just for understanding..
A possible duplicate of the following link
get contact info from android contact picker
Refer to the above link. It has been answered in detail.