RedCorners.Components.DeviceContacts
5.3.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package RedCorners.Components.DeviceContacts --version 5.3.0
NuGet\Install-Package RedCorners.Components.DeviceContacts -Version 5.3.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RedCorners.Components.DeviceContacts" Version="5.3.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add RedCorners.Components.DeviceContacts --version 5.3.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: RedCorners.Components.DeviceContacts, 5.3.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install RedCorners.Components.DeviceContacts as a Cake Addin #addin nuget:?package=RedCorners.Components.DeviceContacts&version=5.3.0 // Install RedCorners.Components.DeviceContacts as a Cake Tool #tool nuget:?package=RedCorners.Components.DeviceContacts&version=5.3.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
NuGet: https://www.nuget.org/packages/RedCorners.Components.DeviceContacts
GitHub: https://github.com/saeedafshari/RedCorners.Components.DeviceContacts
Setting Up / Permissions
iOS
iOS info.plist:
<key>NSContactsUsageDescription</key>
<string>This app requires access to contacts.</string>
Android
Android Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
...>
<application ...>...</application>
<uses-permission android:name="android.permission.READ_CONTACTS" />
</manifest>
MainActivity.cs
protected override void OnCreate(Bundle savedInstanceState)
{
...
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
DeviceContacts.Init(this);
LoadApplication(new App());
...
}
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
{
DeviceContacts.OnRequestPermissionsResult(requestCode, permissions, grantResults);
...
base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
Listing Contacts
var provider = new DeviceContacts();
var contacts = await contacts.GetAllAsync();
It's strongly advised that you check for exceptions there, because GetAllAsync
throws exceptions if the permission to read contacts is not granted:
try
{
var provider = new DeviceContacts();
var contacts = await contacts.GetAllAsync();
}
catch (Exception ex)
{
App.Instance.DisplayAlert("Error", ex.ToString(), "OK");
}
Asking for permissions
When you call await contacts.GetAllAsync()
, the library automatically displays the permission request dialog.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
MonoAndroid | monoandroid80 is compatible. |
Xamarin.iOS | xamarinios10 is compatible. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
MonoAndroid 8.0
- Xamarin.Android.Support.v7.AppCompat (>= 28.0.0.1)
-
Xamarin.iOS 1.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Access device contacts on iOS and Android.