启动应用程序时,我需要检查应用程序是否具有写入设备存储的权限以及访问设备位置的权限。如果没有该应用,则会询问用户这些权限。
为此,我使用下一个代码:
private boolean mayRequestLocations() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
return true;
}
if (checkSelfPermission(ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
return true;
}
if (!shouldShowRequestPermissionRationale(ACCESS_FINE_LOCATION)) {
requestPermissions(new String[]{ACCESS_FINE_LOCATION}, 0);
}
return false;
}
和
private boolean isStoragePermissionGranted() {
if (Build.VERSION.SDK_INT >= 23) {
if (checkSelfPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED) {
return true;
} else {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
return false;
}
} else {
return true;
}
}
我的问题是我想等待该用户接受第一个条件(或关闭我的应用程序),并在授予第一个权限后,该应用程序转到下一步并要求用户允许定位设备。
我认为需要AsyncTask,但不知道如何执行。有什么帮助吗?