mylhyl / androidacp Goto Github PK
View Code? Open in Web Editor NEW一句话搞定,简化Android 6.0 系统复杂的权限操作
一句话搞定,简化Android 6.0 系统复杂的权限操作
java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources$Theme android.content.Context.getTheme()' on a null object reference
at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:241)
at android.app.AlertDialog$Builder.(AlertDialog.java:471)
at com.mylhyl.acp.AcpManager.showDeniedDialog(AcpManager.java:196)
at com.mylhyl.acp.AcpManager.onRequestPermissionsResult(AcpManager.java:185)
at com.mylhyl.acp.AcpActivity.onRequestPermissionsResult(AcpActivity.java:28)
at android.app.Activity.dispatchRequestPermissionsResult(Activity.java:7435)
at android.app.Activity.dispatchActivityResult(Activity.java:7287)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4396)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3660)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3736)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2935)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1648)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:185)
at android.app.ActivityThread.main(ActivityThread.java:6615)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:916)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:806)
java.lang.RuntimeException: Unable to resume activity {com.pufei.gxdt/com.mylhyl.acp.AcpActivity}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=@android:requestPermissions:, request=56, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }} to activity {com.pufei.gxdt/com.mylhyl.acp.AcpActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources$Theme android.content.Context.getTheme()' on a null object reference
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3686)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3736)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2935)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1648)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:185)
at android.app.ActivityThread.main(ActivityThread.java:6615)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:916)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:806)
Caused by: java.lang.RuntimeException: Failure delivering result ResultInfo{who=@android:requestPermissions:, request=56, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }} to activity {com.pufei.gxdt/com.mylhyl.acp.AcpActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources$Theme android.content.Context.getTheme()' on a null object reference
at android.app.ActivityThread.deliverResults(ActivityThread.java:4400)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3660)
... 10 more
您好:
问题描述案例:
申请A权限,当A权限同意之后,之后在业务代码中不能再申请其他权限,申请后 将无法收到任何回调,代码示例如下:
Acp.getInstance(BaseApplication.getContext()).request(AcpOptions.Builder()
.setPermissions(permission.ACCESS_COARSE_LOCATION,)
.build(),
object : AcpListener {
override fun onGranted() {
//权限同意
//部分业务逻辑
Acp.getInstance(){
//这里的权限无法收到回调
}
}
override fun onDenied(permissions: List<String>) {
//权限拒绝
}
})
此类问题,可以通过权限一起申请的方式完成,但是现在对权限管理越来越严格,在代码层面也希望封装成单独申请的模式,如Android 11中前台定位权限 要和后台定位权限分开申请,要先申请前台定位权限,才能申请后台定位权限 。,所以有了上述代码
问题原因:
查看了源码,问题原因在于,当第一次发起申请的时候,权限同意之后,调用了AcpManager的onDestroy方法,将mCallback置位null了,所以嵌套申请的时候 无法正常回调
在onCreate()中申请Manifest.permission.WRITE_EXTERNAL_STORAGE权限时,发生错误
java.lang.NullPointerException: permission cannot be null or empty
如果把targetSdkVersion 修改为23以下,无论是拒绝权限还是同意权限都会走到同意的方法中,你可以会说为什么targetSdkVersion要设置在23以下 都这么老了,这个还是要取决于一些系统设备依赖第三方库的问题 ,不能高于第三方库的targetSdkVersion
我动态获取定位权限,然后点击允许,onGranted这个方法里应该去执行什么?
我就是把一个带位置的h5页面嵌入到 APP 中,现在是获取完定位之后,嵌入的
h5页拿不到手机的定位信息
buildToolsVersion从27.0.3升级到28.0.2后,无法进行权限的升级,而是直接崩溃。
08-28 19:47:35.997 28198-28198/? I/AcpService: targetSdkVersion >= Build.VERSION_CODES.M
08-28 19:47:35.997 28198-28198/? I/AcpManager: checkSelfPermission = -1
08-28 19:47:35.998 28198-28198/? I/AcpService: targetSdkVersion >= Build.VERSION_CODES.M
08-28 19:47:35.998 28198-28198/? I/AcpManager: checkSelfPermission = -1
如题,把targetSdkVersion改成22所有的权限检查都失效了
小米5 Pro 申请不了权限,返回都是以获取了权限,实际是没有获取到权限
如题
在权限申请的填写理由的 有知道了 的对话框上 如果按对话框旁边消除对话框 有问题
LeakCanary 检测内存泄露
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.