PermissionHandler

Additional

Language
Kotlin
Version
N/A
Created
May 15, 2019
Updated
Jun 27, 2019
Owner
Evgen Tretsyak (Rizlee)
Contributor
Evgen Tretsyak (Rizlee)
1
Activity
Badge
Generate
Download
Source code

Advertising

Usage

Gradle

implementation "com.rizlee:permission-handler:$last_version"

Kotlin

private val PERMISSIONS = arrayOf(Manifest.permission.ACCESS_FINE_LOCATION)

override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        requestPermissions()
    }

    private fun requestPermissions() =
        PermissionHandler.requestPermission(this, { permissionsGranted() }, PERMISSIONS)

    private fun permissionsGranted() =
        Toast.makeText(applicationContext, "permissions granted", Toast.LENGTH_SHORT).show()

    override fun onRequestPermissionsResult(
        requestCode: Int,
        permissions: Array<String>,
        grantResults: IntArray
    ) {
        PermissionHandler.permissionsResult(
            this,
            PERMISSIONS,
            requestCode,
            grantResults,
            { permissionsGranted() },
            { Toast.makeText(applicationContext, "permissions unsuccess", Toast.LENGTH_SHORT).show() },
            { Toast.makeText(applicationContext, "permissions error", Toast.LENGTH_SHORT).show() }
        )
    }