I am creating a hybrid mobile application using Xamarin Forms. I want to display a list of all phonebook contacts with the following data:
I added the permission "READ_CONTACTS" in the android manifest. Below is the code to get all contacts:
var contactList = new List < MContacts > ();
var ContactDetailURI = ContactsContract.Contacts.ContentUri;
string[] ContactDetailProjection = {
ContactsContract.Contacts.InterfaceConsts.Id,
ContactsContract.Contacts.InterfaceConsts.DisplayName,
ContactsContract.ContactsColumns.ContactLastUpdatedTimestamp,
ContactsContract.Contacts.InterfaceConsts.PhotoId,
ContactsContract.Contacts.InterfaceConsts.PhotoUri,
ContactsContract.Contacts.InterfaceConsts.PhotoFileId,
ContactsContract.Contacts.InterfaceConsts.PhotoThumbnailUri
};
var ContactDetailCursor = Forms.Context.ContentResolver.Query(
ContactDetailURI,
ContactDetailProjection,
null,
null,
null
);
if (ContactDetailCursor.MoveToFirst()) {
do {
var contact = new MContacts();
contact.Id = ContactDetailCursor.GetLong(ContactDetailCursor.GetColumnIndex(ContactDetailProjection[0]));
contact.DisplayName = ContactDetailCursor.GetString(ContactDetailCursor.GetColumnIndex(ContactDetailProjection[1]));
contact.PhotoId = ContactDetailCursor.GetString(ContactDetailCursor.GetColumnIndex(ContactDetailProjection[6]));
contactList.Add(contact);
} while (ContactDetailCursor.MoveToNext());
}
return contactList;
I have a XAML page that will display data. I am using Image Cell. The following is the XAML code:
<ContentPage.Content>
<ListView x:Name="ContactList">
<ListView.ItemTemplate>
<DataTemplate>
<ImageCell
Text="{Binding DisplayName}"
ImageSource="{Binding PhotoId}">
</ImageCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentPage.Content>
I get the name of the contact, but in the image field I get only this:
content://com.android.contacts/contacts/1/photo
What to do to display the image? What am I missing here?
PS I do not want to use the Xamarin.Mobile component or any other component.
source
share