@AfterPermissionGranted(REQUEST_CODE_SAVE_FILE_PERMISSION)
private void saveFile() {
if (EffortlessPermissions.hasPermissions(this, PERMISSIONS_SAVE_FILE)) {
// We've got the permission.
saveFileWithPermission();
} else {
// Request the permissions.
EffortlessPermissions.requestPermissions(this,
REQUEST_CODE_SAVE_FILE_PERMISSION, PERMISSIONS_SAVE_FILE);
}
}
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
权限拒绝处理
@AfterPermissionDenied(REQUEST_CODE_SAVE_FILE_PERMISSION)
private void onSaveFilePermissionDenied() {
if (EffortlessPermissions.somePermissionDenied(this, PERMISSIONS_SAVE_FILE)) {
// Some permission is permanently denied so we cannot request them normally.
OpenAppDetailsDialogFragment.show(
"",
"App needs permission to save files. Please grant the \"Storage\" permission in system settings.", this);
} else {
// User denied at least some of the required permissions, report the error.
ToastDialog dialog = new ToastDialog(this);
dialog.setText("Save failed: Insufficient permissions");
dialog.show();
}
}
Copyright 2017 Zhang Hai
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.