问题
I am trying to insert the contact from my contacts in phone to my application on select, but unable to do that. on button click from my application i am able to get the list of contacts available in my phone but unable to bind that selected contact data to my application, i think i am unable to uri of the selected contact can you please check my code and suggest me the suitable solution code to do that...
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.New_list);
et = FindViewById<EditText>(Resource.Id.editText1);
var contactPickerIntent = new Intent(Intent.ActionPick,
Android.Provider.ContactsContract.Contacts.ContentUri);
StartActivityForResult(contactPickerIntent, 101);
}
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
var uri = ContactsContract.Contacts.ContentUri;
string[] projection = { ContactsContract.Contacts.InterfaceConsts.Id,
ContactsContract.Contacts.InterfaceConsts.DisplayName };
var cursor = ManagedQuery(uri, projection, null, null, null);
var contactList = new List<string>();
if (cursor.MoveToFirst())
{
do
{//here i am getting entire contact list data but i am unable to
//to get the selected contact data from the entire list
contactList.Add(cursor.GetString(
cursor.GetColumnIndex(projection[1])));
} while (cursor.MoveToNext());
}
}
}
}
来源:https://stackoverflow.com/questions/43519201/how-to-select-the-contact-from-default-contact-list-in-phone-and-insert-it-into