guolindev / permissionx Goto Github PK
View Code? Open in Web Editor NEWAn open source Android library that makes handling runtime permissions extremely easy.
License: Apache License 2.0
An open source Android library that makes handling runtime permissions extremely easy.
License: Apache License 2.0
Manifest.permission.ACCESS_FINE_LOCATION,Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_BACKGROUND_LOCATION
我申请这三个权限,点击拒绝不再提示,为什么request 的allGranted 是true呢,每次进入不应该走onForwardToSettings 强制设置权限么?我想实现即使用户点了拒绝不再提示,重新进app也得强制提示,我用的小米9手机
I got this exception while trying to request the permissions without using .explainReasonBeforeRequest():
https://pastebin.com/6yFKLxg5
Meaning my code works when I do this:
https://pastebin.com/uBmi6R9m
And gives the crash when I do this:
https://pastebin.com/NDjUGMAs
PermissionBuilder #getInvisibleFragment,
private fun getInvisibleFragment(): InvisibleFragment {
...
fragmentManager.beginTransaction().add(invisibleFragment, TAG).commitNow() //此处是不是应该判断StateSaved状态, 或者改成commitNowAllowingStateLoss
}
郭神您好!提个问题,
在Webview中点击网页上传按钮,onShowFileChooser中请求权限时,拒绝和不再提示都不会弹出reason或rational弹窗,即使同意了也没有走到onResult回调中,需要再次点击才能弹出权限框或者文件选择器,而且如果之前选择了不再提示,之后点击上传将没有响应。代码如下:
private boolean hasPermission = false;
@Override
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> valuesCallback, WebChromeClient.FileChooserParams params) {
......
PermissionX.init(WebViewAct.this)
.permissions(Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA)
.onExplainRequestReason(...)
.onForwardToSettings(...)
.request(new RequestCallback() {
@Override
public void onResult(boolean allGranted, List<String> grantedList, List<String> deniedList) {
if (allGranted) {
getFile(webView.getUrl(), acceptType);
}
hasPermission = allGranted;
}
});
return hasPermission;
}
错误信息:
Unable to load class 'org.gradle.api.internal.java.usagecontext.LazyConfigurationUsageContext'.
Possible causes for this unexpected error include:
Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)
The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
Stop Gradle build processes (requires restart)
Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.
In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.
请求蓝牙(Manifest.permission.BLUETOOTH)权限的时候,用户还没点击授权或者拒绝,就直接进入request的回调函数
forwardToSettings 跳转的是应用设置页面,权限请求的话还要在点一下,有些不懂的用户可能不太会操作(需要在一堆设置里面找到权限管理),是否可以直接跳转到应用权限设置页面?
隔壁的方法
mi mix3 android 10版本
targetSdkVersion=29
PermissionX.init(this)
.permissions(ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION, ACCESS_BACKGROUND_LOCATION)
.request { allGranted, grantedList, deniedList ->
println("grantedList:$grantedList")
println("deniedList:$deniedList")
......
}
当点击“仅在使用时访问”,权限被判断为拒绝,日志如下
grantedList:[android.permission.ACCESS_FINE_LOCATION, android.permission.ACCESS_COARSE_LOCATION]
deniedList:[android.permission.ACCESS_BACKGROUND_LOCATION]
启动页不弹出短信权限弹窗 ,进入到首页的时候弹出
我添加权限Manifest.permission.SYSTEM_ALERT_WINDOW,允许访问权限后走的是onForwardToSettings()方法,不是走request()方法,如果不添加Manifest.permission.SYSTEM_ALERT_WINDOW权限,就成功,否则失败
如题
例如:
PermissionX.init(SongInfoActivity.this).permissions(Manifest.permission_group.STORAGE)
我的三星android11申请位置权限申请不到把targetSdkVersion改到29就可以了,麻烦解答下
private String[] mPermissions = {
Manifest.permission.READ_PHONE_STATE,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.CAMERA,
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_BACKGROUND_LOCATION
};
这是我申请的权限
郭神 有没有可能添加 自定义权限申请框功能,我在工程里引用了 但是自定义的好像是 授权前的提示框 和 拒绝后的说明框 ,实际申请权限那个dialog 能否也能自定义
AndPermission就有这个功能,但直接跳转到设置界面,感觉这做法对用户非常不友好
你好,博主
在5.0 和 4.0 的机器运行之后,每次都会走 onForwardToSettings 方法。
引入了PermissionX后Studio老是报 Cause: zip file is empty。升级了Studio(4.0.2)和gradle(6.6.1)之后又报No such property: variantConfiguration for class: com.android.build.gradle.internal.variant.ApplicationVariantData。
后来发现PermissionX的commit记录中有一条“Do not upgrade to gradle plugin 4.0 for now.”
遂放弃PermissionX,哭唧唧。
java.lang.NullPointerException:Attempt to read from field 'java.util.Set k.n.a.d.e.h' on a null object reference
com.permissionx.guolindev.request.InvisibleFragment.d3(InvisibleFragment.java:1)
com.permissionx.guolindev.request.InvisibleFragment.onRequestPermissionsResult(InvisibleFragment.java:1)
androidx.fragment.app.FragmentActivity.onRequestPermissionsResult(FragmentActivity.java:6)
android.app.Activity.dispatchRequestPermissionsResult(Activity.java:8566)
在引导页请求定位权限,在 onCreated 触发权限请求。
不知道用户怎么操作的,出现空指针。
引导页跟踪生命周期:onCreated ----》onResumed -----》onPaused
机型:
三星 SM G975F Android 10,level 29
华为 LYA L29 Android 10,level 29
最近在开发关于读取通讯录的一款App,在开发的过程当中,先使用了PermissionX进行请求可以读写通讯录的操作权限
PermissionUtil.checkContacts(activity,(allGranted, grantedList, deniedList) -> {
if (allGranted){
Log.i(TAG,"权限通过");
}
});
主要读取了以上的权限,但是回调回来的结果竟然是通过,导致项目多次无法正常的运行
现在又抓紧时间使用了其他的方式进行了权限的请求,还望做着可以查一下为什么会出现这样的问题
Caused by: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=131074, result=0, data=null} to activity {com.**/com.ui.activity.backstagesetting.tabmanage.BasicInfoactivity}: kotlin.UninitializedPropertyAccessException: lateinit property permissionBuilder has not been initialized
at android.app.ActivityThread.deliverResults(ActivityThread.java:4333)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3602)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3680)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2924)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1628)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:203)
at android.app.ActivityThread.main(ActivityThread.java:6406)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1113)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:974)
Caused by: kotlin.UninitializedPropertyAccessException: lateinit property permissionBuilder has not been initialized
at com.permissionx.guolindev.InvisibleFragment.onActivityResult(InvisibleFragment.kt:168)
at androidx.fragment.app.FragmentActivity.onActivityResult(FragmentActivity.java:170)
机型:荣耀20 Lite Android10
请求多个权限,仅第一个权限弹出是否开启,其余权限均默认永久关闭,请求示例如下:
PermissionX.init(activity)
.permissions(Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE)
//被用户临时拒绝,查看拒绝选项,走此方法
.onExplainRequestReason { deniedList ->
// val filteredList = deniedList.filter {
// it == Manifest.permission.CAMERA
// }
showRequestReasonDialog(deniedList, "头像设置需要的权限", "我已明白", "取消")
}
//被用户永久拒绝不提醒,走这个方法
.onForwardToSettings { deniedList ->
showForwardToSettingsDialog(deniedList, "您需要去应用程序设置当中手动开启权限", "我已明白", "取消")
}
//allGranted表示是否所有申请的权限都已被授权,grantedList用于记录所有已被授权的权限,deniedList用于记录所有被拒绝的权限
.request { allGranted, _, deniedList ->
if (allGranted) {
singleImg(activity)
} else {
ToastUtil.showShort("您拒绝了如下权限:$deniedList")
}
}
如题,郭神,能加入的话最好了
由InvisibleFragment private lateinit PermissionBuilder 引发 kotlin.UninitializedPropertyAccessException 异常 关键字lateinit 引起 导致未初始化成功 permissionBuilder 为Null
复现操作:
(1) 点击按钮弹出RequestReasonDialog,点击确定。
(2) 允许存储权限,拒绝相机权限。此时会再次弹出RequestReasonDialog。
(3) 点击确定,然后点击禁止后不再提示。此时会弹出ForwardToSettingsDialog。
(4) 点击确定,然后在应用程序权限设置中禁止存储权限。
(5) 再次返回App,App崩溃。
核心代码如下:
PermissionX.init(this)
.permissions(Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.CAMERA)
.explainReasonBeforeRequest()
.onExplainRequestReason(new ExplainReasonCallback() {
@OverRide
public void onExplainReason(ExplainScope scope, List deniedList) {
String message = "该功能需要您同意以下权限才能正常使用";
scope.showRequestReasonDialog(deniedList, message,
"确定", "取消");
}
})
.onForwardToSettings(new ForwardToSettingsCallback() {
@OverRide
public void onForwardToSettings(ForwardScope scope, List deniedList) {
scope.showForwardToSettingsDialog(deniedList,
"您需要去应用程序设置中手动开启以下权限",
"确定", "取消");
}
})
.request(new RequestCallback() {
@OverRide
public void onResult(boolean allGranted, List grantedList, List deniedList) {
if (allGranted) {
}
}
});
版本1.4.0
存储权限,定位权限,同时申请,定位永远在前面,不管我在程序中按什么顺序写的.
应该是以下代码改变了原来list的顺序
PermissionCollection 类中:
public PermissionBuilder permissions(List permissions) {
Set permissionSet = new HashSet<>(permissions);
...
}
发生机型:VIVO V1821A 与 OPPO R11
系统版本:Android 9(vivo),Android 8.1.0(oppo)
ava.lang.NullPointerException
Attempt to read from field 'java.util.Set com.permissionx.guolindev.request.PermissionBuilder.grantedPermissions' on a null object reference
未授予权限,回调中的allGranted 为true
为什么上下文只支持fragmentActivity和fragment呢,感觉好不方便呀
因为PermissionX依赖特定的kotlin版本,可能出现引入的PermissionX所依赖的kotlin版本和当前工程已经在用的kotlin版本不一致,导致编译失败,出现 Cause: duplicate entry: module-info.class 问题。
比如我当前使用的kotlin版本为1.3.72,引入1.4.0版本的permissionx,就出现了上面的问题。而kotlin版本又和gradle插件乃至Android Studio版本都一定关联,所以有时候还不能通过简单地修改一下使用的kotlin版本来解决。
建议郭神在文档里添加版本对应说明,比如工程使用什么版本的kotlin时,应该使用哪个版本的permissionx。虽然对有经验的开发者来说,不是特别难解决的问题,但我觉得对比较初级的朋友们来说会更友好一点。仅仅是一个建议。
java.lang.NullPointerException: Attempt to read from field 'java.util.Set com.permissionx.guolindev.request.PermissionBuilder.grantedPermissions' on a null object reference
很感谢郭神写的库。
上面引起的原因是因为使用Kotlin 会自动创建META-INF/library_release.kotlin_module 文件。可能会和其他库出现冲突。有的解决方案是
android {
.........
packagingOptions {
exclude 'META-INF/library_release.kotlin_module'
}
}
但是这个对我没作用,因为我本地有一个library库,和你的库名字一样了,然后生成的也一样了,就报错了,我用这种方式的话,会导致项目不能用,我现在把本地的库名字改了,就可以了。
不过这个可以在库上解决根本原因,这样就避免了让每个人都添加排除修复程序:
ChuckerTeam/chucker#134
每次使用,都得自己new一个对象,有没有办法做一个全局的方法,把context传给我,然后我统一new一个弹窗给你传回去呢?
郭神,在添加1.4.0版本依赖后,我在Activity中重写attachBaseContext方法切换多语言资源文件的方法会失效但没有报错,即Activity级的Resources切换失败,但是Application级的Resources是能成功切换的,说明代码没有问题。
将依赖版本切换回1.3.0版本则没有这个问题,我测试的时候没有使用PermissionX的方法,仅仅添加依赖就会出现这个问题,求解啊
Redmi Note3,Android5.0.2,应用权限全部关闭后,申请权限的时候走了成功回调
在ViewPager的其中一个fragment中使用PermissionX出现了以下报错:
Caused by: java.lang.IllegalStateException: FragmentManager is already executing transactions
at androidx.fragment.app.FragmentManagerImpl.ensureExecReady(FragmentManagerImpl.java:1660)
at androidx.fragment.app.FragmentManagerImpl.execSingleAction(FragmentManagerImpl.java:1692)
at androidx.fragment.app.BackStackRecord.commitNow(BackStackRecord.java:293)
at com.permissionx.guolindev.request.PermissionBuilder.getInvisibleFragment(PermissionBuilder.java:275)
at com.permissionx.guolindev.request.PermissionBuilder.requestNow(PermissionBuilder.java:252)
at com.permissionx.guolindev.request.RequestNormalPermissions.request(RequestNormalPermissions.java:62)
at com.permissionx.guolindev.request.RequestChain.runTask(RequestChain.java:55)
是不是没有适配Android11啊,MANAGE_EXTERNAL_STORAGE申请有问题,不弹窗直接拒绝
PermissionX.init(this)
.permissions(Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE)
/.onExplainRequestReason(new ExplainReasonCallbackWithBeforeParam() {
@OverRide
public void onExplainReason(ExplainScope scope, List deniedList, boolean beforeRequest) {
scope.showRequestReasonDialog(deniedList, "即将申请的权限是程序必须依赖的权限", "我已明白");
}
})/
/* .onForwardToSettings(new ForwardToSettingsCallback() {
@OverRide
public void onForwardToSettings(ForwardScope scope, List deniedList) {
scope.showForwardToSettingsDialog(deniedList, "您需要去应用程序设置当中手动开启权限", "我已明白");
}
})*/
.request(new RequestCallback() {
@OverRide
public void onResult(boolean allGranted, List grantedList, List deniedList) {
if (allGranted) {
new CameraUtil(getContext()).showCamera();
Toast.makeText(MainActivity.this, "所有申请的权限都已通过", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainActivity.this, "您拒绝了如下权限:" + deniedList, Toast.LENGTH_SHORT).show();
}
}
});
});
为甚使用scop 显示dialog 会出现 右边贴着屏幕,左边正常
首先说明框架没问题,是我用的问题,由于水平较低,不知道怎么处理是比较稳妥的,所以提个问题。Demo中 是在按钮点击时间里面去应用的框架,CustomDialogFragment 弹窗是没问题的,但是我们需求是启动activity后 去检测权限,所以我直接把代码放到onCreate 中,
@OverRide
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_java);
PermissionX.init(MainJavaActivity.this)
.permissions(Manifest.permission.WRITE_EXTERNAL_STORAGE)
.explainReasonBeforeRequest()
.onExplainRequestReason(new ExplainReasonCallbackWithBeforeParam() {
@OverRide
public void onExplainReason(ExplainScope scope, List deniedList, boolean beforeRequest) {
CustomDialogFragment dialog = new CustomDialogFragment("请允许权限选择", deniedList);
scope.showRequestReasonDialog(dialog);
}
}).onForwardToSettings(new ForwardToSettingsCallback() {
@OverRide
public void onForwardToSettings(ForwardScope scope, List deniedList) {
CustomDialogFragment dialog = new CustomDialogFragment("请允许权限选择,去设置", deniedList);
scope.showForwardToSettingsDialog(dialog);
}
}).request(new RequestCallback() {
@OverRide
public void onResult(boolean allGranted, List grantedList, List deniedList) {
if (allGranted) {
Toast.makeText(MainJavaActivity.this, "All permissions are granted", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainJavaActivity.this, "The following permissions are denied:" + deniedList, Toast.LENGTH_SHORT).show();
}
}
});
}
但是获取控件为空
View positiveButton = dialogFragment.getPositiveButton();
View negativeButton = dialogFragment.getNegativeButton();
请教郭神这种情况怎么处理比较好
只需要打开屏幕旋转开关,在弹出权限对话框后,把手机横过来,等所有权限申请结束后,Activity接收不到任何响应。
使用项目中的演示app就可以还原,如视频所示:
点击下载视频
依赖 permissionx:1.2.2
...
scope.showRequestReasonDialog(deniedList, “需要您同意以下权限才能正常使用”, "允许请求", "我还是拒绝")
...
权限被拒绝时,弹默认dialog,设置的确认、拒绝按钮文案没有正常显示
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.