Last active
March 29, 2019 12:22
-
-
Save satoshun/51e73ff509363dcdf7d463695d2fe6f1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.github.satoshun.example | |
// sample code | |
@RuntimePermissions | |
internal class HogeFragment : Fragment() { | |
@NeedsPermission(Manifest.permission.CAMERA) | |
fun camera() { | |
TODO() | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This file was generated by PermissionsDispatcher. Do not modify! | |
@file:JvmName("HogeFragmentPermissionsDispatcher") | |
package com.github.satoshun.example | |
import kotlin.Array | |
import kotlin.Int | |
import kotlin.IntArray | |
import kotlin.String | |
import permissions.dispatcher.PermissionUtils | |
private val REQUEST_CAMERA: Int = 0 | |
private val PERMISSION_CAMERA: Array<String> = arrayOf("android.permission.CAMERA") | |
fun HogeFragment.cameraWithPermissionCheck() { | |
if (PermissionUtils.hasSelfPermissions(this.requireActivity(), *PERMISSION_CAMERA)) { | |
camera() | |
} else { | |
this.requestPermissions(PERMISSION_CAMERA, REQUEST_CAMERA) | |
} | |
} | |
fun HogeFragment.onRequestPermissionsResult(requestCode: Int, grantResults: IntArray) { | |
when (requestCode) { | |
REQUEST_CAMERA -> | |
{ | |
if (PermissionUtils.verifyPermissions(*grantResults)) { | |
camera() | |
} | |
} | |
} | |
} |
Author
satoshun
commented
Mar 29, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment