I tried to use plugin Xamarin.Forms.Contacts
and followed the github link,
https://gist.github.com/enisn/25fd0a63a849854fb6103aa681be9963
But, when I compile and debug nothing is shown on screen. I added the plugin to Android and iOS also and setup the required permissions.
In the first line of GetContacts()
Debugger dies and does not move to another line.
public ContactList()
{
InitializeComponent();
GetContacs();
}
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
async Task GetContacs()
{
var contacts = await Plugin.ContactService.CrossContactService.Current.GetContactListAsync();
lstContacts.BindingContext = contacts;
},
I also followed the tutorial on link, https://www.xamboy.com/2019/10/10/getting-phone-contacts-in-xamarin-forms/ In this tutorial, i found issue with the permission function, debugger dies here also, in the if condition to verify permissions.
`public async Task<bool> RequestPermissionAsync()
{
contactPermissionTcs = new TaskCompletionSource<bool>();
// Verify that all required contact permissions have been granted.
if (Android.Support.V4.Content.ContextCompat.CheckSelfPermission(CrossCurrentActivity.Current.Activity, Manifest.Permission.ReadContacts) != (int)Permission.Granted
|| Android.Support.V4.Content.ContextCompat.CheckSelfPermission(CrossCurrentActivity.Current.Activity, Manifest.Permission.WriteContacts) != (int)Permission.Granted)
{
// Contacts permissions have not been granted.
RequestContactsPermissions();
}
else
{
// Contact permissions have been granted.
contactPermissionTcs.TrySetResult(true);
}
return await contactPermissionTcs.Task;
}`
This also did not work.
Is there anyway or suggestion that would make my task easier?