【发布时间】:2018-05-19 03:11:47
【问题描述】:
我在xamarin 遇到问题,我需要一些帮助
来自xamarin 教程,感谢DependencyService,我希望拨打电话。
这是Android部分的服务实现:
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;
}
主要问题是:我有一个被撤销的权限
android.permission.CALL_PHONE
。我确切地说我已经在manifest 中给予了许可。我已阅读我需要在运行时注册权限。这就是我正在尝试的
ActivityCompat.RequestPermissions(activity,
new String[] { Android.Manifest.Permission.CallPhone }, 1);
但我需要当前的 Activity 作为参数,我无法将当前的 Context 转换为 Activity。
请帮我找出我做错的地方。
谢谢
【问题讨论】: