PermissionX is a versatile library designed to streamline permission requests across various Android versions, ensuring a consistent and simplified approach. Its primary purpose is to enable developers to define version-specific ranges for requesting permissions, such as differentiating between "Read External Storage" for SDK version 32 and below, and "Read Media" for versions above. Additionally, PermissionX facilitates the handling of permissions introduced in newer Android versions, such as "Post Notification," allowing seamless requests without the need for manual version checks or complex management. This makes it an invaluable tool for developers aiming to enhance code maintainability and ensure compatibility with evolving Android APIs.
In your project-level build.gradle or settings.gradle file, add the JitPack repository:
repositories {
google()
mavenCentral()
maven { url "https://jitpack.io" }
}
In your app-level build.gradle file, add the library dependency. Use the latest version:
Groovy Version
implementation 'com.github.hypersoftdev:PermissionX:x.x.x'
Kts Version
implementation("com.github.hypersoftdev:PermissionX:x.x.x")
val singlePermission = listOf(
ItemPermissionX(
intRange = (Int.MIN_VALUE..Int.MAX_VALUE),
permissionList = arrayListOf(Manifest.permission.CAMERA),
)
)
val multiplePermissionsList = listOf(
ItemPermissionX(
intRange = (Build.VERSION_CODES.TIRAMISU..Int.MAX_VALUE),
permissionList = arrayListOf(
Manifest.permission.CAMERA,
Manifest.permission.READ_MEDIA_IMAGES,
Manifest.permission.READ_MEDIA_VIDEO,
Manifest.permission.READ_MEDIA_AUDIO,
Manifest.permission.POST_NOTIFICATIONS
),
),
ItemPermissionX(
intRange = (Build.VERSION_CODES.Q..Build.VERSION_CODES.S),
permissionList = arrayListOf(
Manifest.permission.CAMERA,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.ACCESS_MEDIA_LOCATION
),
),
ItemPermissionX(
intRange = (Int.MIN_VALUE..Build.VERSION_CODES.P),
permissionList = arrayListOf(
Manifest.permission.CAMERA,
Manifest.permission.READ_EXTERNAL_STORAGE
),
)
)
We can give different sdk range for asking different permission for variety of sdk versions
permissionManager.requestPermissionsByDynamicSDK(
sdkPermissionsList = permissionsToAsk, //Replace permissionsToAsk with singlePermission or multiplePermissionsList
) { allGranted, deniedPermissions ->
if (allGranted) {
// All permissions granted for this SDK version
Log.d("Permissions", "All granted")
} else {
// Handle denied permissions
Log.d("Denied Permissions", deniedPermissions.toString())
}
}
This work would not have been possible without the invaluable contributions of Abdul Moiz. His expertise, dedication, and unwavering support have been instrumental in bringing this project to fruition.
We are deeply grateful for AbdulMoiz involvement and his belief in the importance of this work. His contributions have made a significant impact, and we are honored to have had the opportunity to collaborate with him.
Copyright 2023 Hypersoft Inc
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.