代码拉取完成,页面将自动刷新
Android平台运行时动态申请权限库, 我的目标是 —— 简单且易用。 Readme_English.md
implementation 'com.github.warkiz.ferrypermission:ferrypermission:1.0.0'
使用前确保权限已经在AndroidManifest.xml文件中注册.
new FerryPermission(this)
.request(Manifest.permission.CAMERA) //申请的照相权限
.observe(new PureResultListener() {
@Override
public void result(boolean isGranted) {
if (isGranted) {
//获得权限,继续下一步.
} else {
//权限拒绝.
}
}
});
new FerryPermission(this)
.request(Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE)
.observeCombined(new CombinedResultListener() { //组合式申请,结果回调一次
@Override
public void result(Permission permission) {
if (permission.isGranted) {
//获得所有权限,继续下一步.
} else if (permission.shouldShowRequestPermissionRationale) {
//至少有一个权限被拒绝并且下次会再次询问.
} else {
//至少有一个权限被拒绝并且不再询问
//引导用户至设置页手动授权
}
}
});
new FerryPermission(this)
.request(Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE)
.observeEach(new EachResultListener() {
@Override
public void result(Permission permission) {//回调两次,即每个权限各一次
if (permission.isGranted) {
//获得权限。可获取权限名为 permission.name
} else if (permission.shouldShowRequestPermissionRationale) {
//权限被拒绝,但会再次询问。
} else {
//权限被拒绝,不再询问。
}
}
});
在API level 23(Marshmallow) 之前,权限会自动交给系统去判断。
最后如果对此项目有疑问, 欢迎通过下面的方式联系我.
Copyright (C) 2018 zhuangguangquan warkiz
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.
内容可能含有违规信息
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。