还记得android棉花糖上的请求权限吗
在我的活动中,我可以使用以下代码行处理android 6中的危险权限:还记得android棉花糖上的请求权限吗,android,android-activity,android-6.0-marshmallow,Android,Android Activity,Android 6.0 Marshmallow,在我的活动中,我可以使用以下代码行处理android 6中的危险权限: ActivityCompat.requestPermissions(WriteThreadActivity.this, new String[]{android.Manifest.permission.READ_EXTERNAL_STORAGE, android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, R
ActivityCompat.requestPermissions(WriteThreadActivity.this,
new String[]{android.Manifest.permission.READ_EXTERNAL_STORAGE,
android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, RESULT_LOAD_IMAGE);
它工作正常,但是否有任何方法可以防止用户每次打开此活动时显示此弹出窗口?例如记住方法?您不需要请求读取\u外部\u存储权限。如果您请求写入\u外部\u存储,因为它位于同一权限组中,它将自动获得访问权限。
// Here, thisActivity is the current activity
if (ContextCompat.checkSelfPermission(thisActivity,
Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
// Show an expanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(thisActivity,
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE);
// MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE is an
// app-defined int constant. The callback method gets the
// result of the request.
}
}else{
// You have permission granted already, to the task
}
private boolean doesUserHavePermission()
{
int result = context.checkCallingOrSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
return result == PackageManager.PERMISSION_GRANTED;
}