当我移到另一个选项卡时,我只是请求位置(ACCESS_FINE_LOCATION)的运行时权限,那个时间的应用程序崩溃了。
private void RequestPermissions()
{
try
{
bool shouldProvideRationale = Android.Support.V4.App.ActivityCompat.ShouldShowRequestPermissionRationale(Activity, Manifest.Permission.AccessFineLocation);
if (shouldProvideRationale)
{
Log.Info(Tag, "Displaying permission rationale to provide additional context.");
}
else
{
Android.Support.V4.App.ActivityCompat.RequestPermissions(Activity, new String[] { Manifest.Permission.AccessFineLocation }, 1);
Log.Info(Tag, "Requesting permission");
// StartLocationPermissionRequest();
}
}
}
我需要弹出窗口一直停留到我响应该许可为止。
答案 0 :(得分:0)
您是否已在清单中声明许可? 如果不是,请转到AndroidManifest.xml并添加:< 使用权限android:name =“ android.permission.ACCESS_FINE_LOCATION” />
答案 1 :(得分:0)
对于完全相同的事情,我有一个可行的解决方案,如下所示:
在您的OnCreate方法中检查现有权限:
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
授予“检查权限”的方法如下:
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
“请求”许可权代码如下所示:
if (!(CheckPermissionGranted(Manifest.Permission.AccessCoarseLocation) &&
CheckPermissionGranted(Manifest.Permission.AccessFineLocation)))
{
RequestLocationPermission();
}
else
{
InitializeLocationManager();
}
InitPageWidgets();
一旦接受或拒绝此权限,该方法就会被调用:
[Export]
public bool CheckPermissionGranted(string Permissions)
{
// Check if the permission is already available.
if (ActivityCompat.CheckSelfPermission(this, Permissions) != Permission.Granted)
{
return false;
}
else
{
return true;
}
}