Skip to content

Instantly share code, notes, and snippets.

@satoshun
Last active March 29, 2019 12:22
Show Gist options
  • Save satoshun/51e73ff509363dcdf7d463695d2fe6f1 to your computer and use it in GitHub Desktop.
Save satoshun/51e73ff509363dcdf7d463695d2fe6f1 to your computer and use it in GitHub Desktop.
package com.github.satoshun.example
// sample code
@RuntimePermissions
internal class HogeFragment : Fragment() {
@NeedsPermission(Manifest.permission.CAMERA)
fun camera() {
TODO()
}
}
// 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()
}
}
}
}
@satoshun
Copy link
Author

> Task :app:compileDebugKotlin FAILED
e: app/build/generated/source/kapt/debug/com/github/satoshun/example/HogeFragmentPermissionsDispatcher.kt: (16, 5): 'public' member exposes its 'internal' receiver type HogeFragment
e: app/build/generated/source/kapt/debug/com/github/satoshun/example/HogeFragmentPermissionsDispatcher.kt: (24, 5): 'public' member exposes its 'internal' receiver type HogeFragment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment