AndroidManifest, runtime permission requests, best practices.
Declaring Permissions
<!-- Platforms/Android/AndroidManifest.xml -->
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
Requesting at Runtime
public static async Task<bool> RequestCameraAsync()
{
var status = await Permissions.CheckStatusAsync<Permissions.Camera>();
if (status == PermissionStatus.Granted) return true;
// Show rationale before requesting
bool proceed = await Shell.Current.DisplayAlert(
"Camera Access",
"We need camera access to take profile photos.",
"Allow", "Deny");
if (!proceed) return false;
status = await Permissions.RequestAsync<Permissions.Camera>();
return status == PermissionStatus.Granted;
}
Key Takeaways
Declare ALL needed permissions in AndroidManifest.xml first
Check permission status before attempting to use protected features
Always explain to the user why you need the permission before requesting it
If permanently denied, guide users to Settings to enable manually