Hello,
Welcome to our Microsoft Q&A platform!
If you want to use AndroidX package, you should migrate your application to AndroidX, please refer to the following doc step by step.
https://learn.microsoft.com/en-us/xamarin/android/platform/androidx
After that, please set the Target Framework to Android 10 or later like following screenshot.
Then you can get the AndroidX packages.
Another way to request permission. If you use Xamarin. I recommand you to use Xamarin.Essentials: Permissions. install Xamarin.Essentials
nuget packages(If you did not install it).
Then Use following code in your activity.
public class MainActivity : AppCompatActivity
{
public int REQUEST_LOCATION;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
CheckAndRequestMicrophonePermission();
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.activity_main);
}
public async Task<PermissionStatus> CheckAndRequestMicrophonePermission()
{
var status = await Permissions.CheckStatusAsync<Permissions.Microphone>();
if (status == PermissionStatus.Granted)
return status;
if (Permissions.ShouldShowRationale<Permissions.Microphone>())
{
// Prompt the user with additional information as to why the permission is needed
}
status = await Permissions.RequestAsync<Permissions.Microphone>();
return status;
}
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);
}
}
}
Best Regards,
Leon Lu
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.