Reputation: 610
Hey Good Day Everyone I am using Xamarin.Mobile but I got error on Permission Denied I already added the READ_CONTACTS in AndroidManifest and also Add permission at runtime. How to solve this?
Method
public async Task<IEnumerable<MobileUserContact>> GetAllContacts()
{
if (_contacts != null) return _contacts;
var contacts = new List<MobileUserContact>();
await _book.RequestPermission().ContinueWith(t =>
{
if (!t.Result)
{
Log.Debug("PERM", "Permission Denied!");
return;
}
foreach (var contact in _book.Where(c => c.Emails.Any())) // Filtering the Contact's that has E-Mail addresses
{
var firstOrDefault = contact.Emails.FirstOrDefault();
if (firstOrDefault != null)
{
contacts.Add(new MobileUserContact()
{
ContactFirstName = contact.FirstName,
ContactLastName = contact.LastName,
ContactDisplayName = contact.DisplayName,
ContactEmailId = firstOrDefault.Address,
ContactNumber = contact.Phones.ToString()
});
}
}
});
_contacts = (from c in contacts orderby c.ContactFirstName select c).ToList();
return _contacts;
}
Upvotes: 3
Views: 582
Reputation: 655
Looks like you'r not asking for user permission to access their contacts.
Take a look in here: https://github.com/jamesmontemagno/PermissionsPlugin and I would advise to use this one too: https://github.com/jamesmontemagno/Xamarin.Plugins/tree/master/Contacts
Upvotes: 2