File tree Expand file tree Collapse file tree 1 file changed +39
-1
lines changed Expand file tree Collapse file tree 1 file changed +39
-1
lines changed Original file line number Diff line number Diff line change 1
1
# JPermission
2
2
Android(安卓)基于注解的6.0权限动态申请
3
3
4
+ # 支持的场景
5
+ 1 . activity
6
+ 2 . fragment
7
+ 3 . service
8
+ 4 . 自定义view
9
+ 5 . 无上下文的类中(需要通过 JPermissionHelper 注入context)
10
+
4
11
# 如何接入
5
12
1、在项目的gradle中添加如下代码
6
13
```
@@ -35,7 +42,7 @@ apply plugin: 'android-aspectjx' //添加这一行
35
42
```
36
43
在依赖中增加:
37
44
```
38
- implementation 'com.github.zincPower:JPermission:0.4 '
45
+ implementation 'com.github.zincPower:JPermission:0.5 '
39
46
```
40
47
41
48
# 简单使用
@@ -66,6 +73,37 @@ private void deny(DenyInfo denyInfo) {
66
73
JPermissionUtil.goToMenu(context);
67
74
```
68
75
76
+ # 无上下文的类中如何使用
77
+ 1、需要通过 JPermissionHelper 提供一个context,** 当然不注入也能正常使用,但只能在有上下文的类中使用** ,注入代码如下
78
+ ```
79
+ JPermissionHelper.injectContext(this);
80
+ ```
81
+ > 温馨提示:为了避免内存泄漏,请于Application中注入
82
+
83
+ 2、无上下文的类中如下编写(用法与第一点“简单使用”一样),只需要在需要的地方调用对应的方法。例如调用此处的requestInNormalClass方法即可
84
+ ```
85
+ public class NoneContext {
86
+
87
+ private final String TAG = NoneContext.class.getSimpleName();
88
+
89
+ @Permission(value = {Manifest.permission.ACCESS_FINE_LOCATION}, requestCode = 200)
90
+ public void requestInNormalClass() {
91
+ Log.i(TAG, "请求定位权限成功,200");
92
+ }
93
+
94
+ @PermissionCanceled()
95
+ private void cancel(CancelInfo cancelInfo) {
96
+ Log.i(TAG, "cancel:" + cancelInfo.getRequestCode());
97
+ }
98
+
99
+ @PermissionDenied()
100
+ private void deny(DenyInfo denyInfo) {
101
+ Log.i(TAG, "deny [code:" + denyInfo.getRequestInfo() + " ; deny:" + denyInfo.getDeniedPermissions() + "]");
102
+ }
103
+
104
+ }
105
+ ```
106
+
69
107
# 高级使用
70
108
1、请求manifest中的所有权限(主要用于app开启时,进行一次权限请求)
71
109
```
You can’t perform that action at this time.
0 commit comments