We will use the Xam.Plugin.Media NuGet package to access the photo library of the device. We need to install this package for the Chat-, Chat.iOS, and Chat.Android projects in the solution. Before we can use the package, however, we need to do some configuration for each platform. We will start with Android:
- The plugin needs the WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE permissions. The plugin will add these for us, but we need to override OnRequestPermissionResult in MainActivity.cs first.
- Call the OnRequestPermissionsResult method.
- Add CrossCurrentActivity.Current.Init(this, savedInstanceState) after initializing Xamarin.Forms in the OnCreate method in the MainActivity.cs file, as shown in the following code:
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Android.Content.PM.Permission[] grantResults)
{
Xamarin.Essentials.Platform.OnRequestPermissionsResult...