Skip to content

Commit

Permalink
Create README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
memishood authored Feb 18, 2021
1 parent e80c29a commit c844b7b
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
## Check & Request the permissions with Ask-Permissions-Android

### Download
#### 1.Add this in your root `build.gradle` at the end of repositories:
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}

#### 2.Add this dependency in your app level `build.gradle`:
dependencies {
...
def ask_permissions_version = "1.0.0"
implementation "com.github.memishood:android-ask-permissions:$ask_permissions_version"
}

### 2. In your project:

```kotlin
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
binding.button.setOnClickListener {
if (check(this, Manifest.permission.CAMERA)) {
Log.d(TAG, "onCreate: permissions granted")
} else {
Log.d(TAG, "onCreate: permissions not granted")
ask(this, Manifest.permission.CAMERA)
Log.d(TAG, "onCreate: permissions asked")
}
}
}

override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (check(activity = this, permissions = permissions)) {
Log.d(TAG, "onRequestPermissionsResult: Permissions granted after dialog")
} else {
Log.d(TAG, "onRequestPermissionsResult: Permissions rejected after dialog")
}
}
```

0 comments on commit c844b7b

Please sign in to comment.