how to select the contact from default contact list in phone and insert it into my application in xamarin.android

拜拜、爱过 提交于 2019-12-08 05:00:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!