For Android, we need to set up the app so that it requires the following two permissions:
- ACCESS_COARSE_LOCATION
- ACCESS_FINE_LOCATION
We can set this in the AndroidManifest.xml file, which can be found in the Properties folder in the Weather.Android project. However, we can also set this in the project properties on the Android Manifest tab, as shown in the following screenshot:
When we request permissions in an Android app, we also need to add the following code to the MainActivity.cs file in the Android project:
public override void OnRequestPermissionsResult(int requestCode, string[] permissions,
[GeneratedEnum] Android.Content.PM.Permission[] grantResults)
{
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults); base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
For Android, we also need to initialize Xamarin.Essentials. We will do this...