权限被拒绝使用Xamarin.Mobile访问联系人列表xamarin.form

时间:2016-07-28 08:01:53

标签: xamarin xamarin.android xamarin.forms xamarin-studio

嘿,好日子每个人我都在使用Xamarin.Mobile,但我在权限被拒绝时遇到错误我已经在AndroidManifest中添加了READ_CONTACTS,并在运行时添加了权限。怎么解决这个?

方法

    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;
    }

1 个答案:

答案 0 :(得分:2)

您似乎没有要求用户访问其联系人的权限。

在这里查看:https://github.com/jamesmontemagno/PermissionsPlugin 我也建议使用这个:https://github.com/jamesmontemagno/Xamarin.Plugins/tree/master/Contacts