Skip to content

ssseasonnn/PermissionX

Repository files navigation

PermissionX

申请权限也能使用协程?Why not?

准备

  1. Add jitpack to build.gradle
allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
  1. Add dependency
dependencies {
	implementation 'com.github.ssseasonnn:PermissionX:1.0.2'
}

使用方法

权限申请只需一行代码

launch {
    try {
        val result = request(READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE)
        if (result.isGranted) {
            //Now we have storage permission.
        }else {
            if (result.shouldShowRational) {
                //Show permission rational
            }
            if (result.alwaysDenied) {
                //User always denied our permission
            }
        }
    } catch (t: Throwable) {
        Log.w("TAG", t)
    }
}

License

Copyright 2021 Season.Zlc

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.

About

Android permission with coroutine

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages