I have an issue in xamarin
, and I need some help, please
From xamarin
tutorial, I wish to launch a phone call thanks to a DependencyService
.
Here is the service implementation for Android part:
public bool Dial(string number)
{
var context = Android.App.Application.Context;
if (context == null)
return false;
var intent = new Intent(Intent.ActionCall);
intent.SetData(Uri.Parse("tel:" + number));
try
{
var activity = (Activity)context;
ActivityCompat.RequestPermissions(activity,
new String[] { Android.Manifest.Permission.CallPhone }, 1);
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
if (IsIntentAvailable(context, intent))
{
try
{
context.StartActivity(intent);
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
return true;
}
return false;
}
The main issue is: I have a revoked permission
android.permission.CALL_PHONE
. I precise that I have given the permission in the manifest
. I have read that I need to register in runtime the permission. It's what I'm trying with
ActivityCompat.RequestPermissions(activity,
new String[] { Android.Manifest.Permission.CallPhone }, 1);
But I need the curent Activity as parameter and I can't cast the current Context into Activity
.
Please help me to find where I have done a mistake.
Thank you