You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In big projects, app is generally divided in several modules and in such cases, if any individual
24
-
module is just a data module (_not having UI_) and need to know state of a permission, it's not
25
-
that easy. This library provides a way to know state of a permission throughout the app and
26
-
from any layer of the application safely.
23
+
In big projects, app is generally divided in several modules and in such cases, if any individual
24
+
module is just a data module (_not having UI_) and need to know state of a permission, it's not
25
+
that easy. This library provides a way to know state of a permission throughout the app and
26
+
from any layer of the application safely.
27
27
28
28
_For example, you can listen for state of contacts permission in class where you'll instantly show
29
-
list of contacts when permission is granted._
29
+
list of contacts when permission is granted._
30
30
31
31
It's a simple and easy to use library. Just Plug and Play.
32
32
@@ -49,23 +49,9 @@ dependencies {
49
49
50
50
_You can find latest version and changelogs in the [releases](https://github.com/PatilShreyas/permission-flow-android/releases)_.
51
51
52
-
### 2. Initialization
52
+
### 2. Observing a Permission State
53
53
54
-
Before using any API of the library, it needs to be initialized before.
55
-
Initialize **PermissionFlow** as follows (For example, in `Application` class):
56
-
57
-
```kotlin
58
-
classMyApplication: Application() {
59
-
overridefunonCreate() {
60
-
super.onCreate()
61
-
PermissionFlow.init(this)
62
-
}
63
-
}
64
-
```
65
-
66
-
### 3. Observing a Permission State
67
-
68
-
#### 3.1 Observing Permission with `StateFlow`
54
+
#### 2.1 Observing Permission with `StateFlow`
69
55
A permission state can be subscribed by retrieving `StateFlow<PermissionState>` or `StateFlow<MultiplePermissionState>` as follows:
70
56
71
57
```kotlin
@@ -101,7 +87,7 @@ suspend fun observeMultiplePermissions() {
101
87
}
102
88
```
103
89
104
-
#### 3.2 Observing permissions in Jetpack Compose
90
+
#### 2.2 Observing permissions in Jetpack Compose
105
91
106
92
State of a permission and state of multiple permissions can also be observed in Jetpack Compose application as follows:
107
93
@@ -119,29 +105,29 @@ fun ExampleSinglePermission() {
119
105
@Composable
120
106
funExampleMultiplePermission() {
121
107
val state by rememberMultiplePermissionState(
122
-
Manifest.permission.CAMERA
108
+
Manifest.permission.CAMERA,
123
109
Manifest.permission.ACCESS_FINE_LOCATION,
124
110
Manifest.permission.READ_CONTACTS
125
111
)
126
-
112
+
127
113
if (state.allGranted) {
128
114
// Render something
129
115
}
130
-
116
+
131
117
val grantedPermissions = state.grantedPermissions
132
118
// Do something with `grantedPermissions`
133
-
119
+
134
120
val deniedPermissions = state.deniedPermissions
135
121
// Do something with `deniedPermissions`
136
122
}
137
123
```
138
124
139
-
### 4. Requesting permission with PermissionFlow
125
+
### 3. Requesting permission with PermissionFlow
140
126
141
-
It's necessary to use utilities provided by this library to request permissions so that whenever permission state
127
+
It's necessary to use utilities provided by this library to request permissions so that whenever permission state
142
128
changes, this library takes care of notifying respective flows.
143
129
144
-
#### 4.1 Request permission from Activity / Fragment
130
+
#### 3.1 Request permission from Activity / Fragment
145
131
146
132
Use [`registerForPermissionFlowRequestsResult()`](https://patilshreyas.github.io/permission-flow-android/docs/permission-flow/dev.shreyaspatil.permissionFlow.utils/register-for-permission-flow-requests-result.html) method to get `ActivityResultLauncher`
147
133
and use `launch()` method to request for permission.
@@ -157,7 +143,7 @@ class ContactsActivity : AppCompatActivity() {
157
143
}
158
144
```
159
145
160
-
#### 4.2 Request permission in Jetpack Compose
146
+
#### 3.2 Request permission in Jetpack Compose
161
147
162
148
Use [`rememberPermissionFlowRequestLauncher()`](https://patilshreyas.github.io/permission-flow-android/docs/permission-flow-compose/dev.shreyaspatil.permissionflow.compose/remember-permission-flow-request-launcher.html) method to get `ManagedActivityResultLauncher`
163
149
and use `launch()` method to request for permission.
@@ -166,17 +152,17 @@ and use `launch()` method to request for permission.
166
152
@Composable
167
153
funExample() {
168
154
val permissionLauncher = rememberPermissionFlowRequestLauncher()
### 5. Manually notifying permission state changes ⚠️
162
+
### 4. Manually notifying permission state changes ⚠️
177
163
178
-
If you're not using `ActivityResultLauncher` APIs provided by this library then
179
-
you will ***not receive permission state change updates***. But there's a provision by which
164
+
If you're not using `ActivityResultLauncher` APIs provided by this library then
165
+
you will ***not receive permission state change updates***. But there's a provision by which
180
166
you can help this library to know about permission state changes.
181
167
182
168
Use [`PermissionFlow#notifyPermissionsChanged()`](https://patilshreyas.github.io/permission-flow-android/docs/permission-flow/dev.shreyaspatil.permissionFlow/-permission-flow/notify-permissions-changed.html) to notify the permission state changes
[Visit the API documentation](https://patilshreyas.github.io/permission-flow-android/docs/) of this library to get more information in detail. This documentation is generated using [Dokka](https://github.com/Kotlin/dokka).
@@ -221,11 +243,11 @@ fun doSomething() {
221
243
222
244
---
223
245
224
-
## 🙋♂️ Contribute
246
+
## 🙋♂️ Contribute
225
247
226
248
Read [contribution guidelines](CONTRIBUTING.md) for more information regarding contribution.
227
249
228
-
## 💬 Discuss?
250
+
## 💬 Discuss?
229
251
230
252
Have any questions, doubts or want to present your opinions, views? You're always welcome. You can [start discussions](https://github.com/PatilShreyas/permission-flow-android/discussions).
Copy file name to clipboardExpand all lines: app/src/main/java/dev/shreyaspatil/permissionFlow/example/ui/composePermission/ComposePermissionActivity.kt
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -49,7 +49,7 @@ private val permissions = arrayOf(
0 commit comments