Direct Android activity and permission result
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.idea
buildSrc
cameraview @ 3eaeac0
demo
dispatcher
gradle/wrapper
.gitignore
.gitmodules
LICENSE
README.md
build.gradle.kts
gradle.properties
gradlew
gradlew.bat
settings.gradle.kts

README.md

Dispatcher

bintray download build license

Kotlin-focused library to simplify the process of handling result from an Activity and requesting permissions.

  • Direct activity and permission result. Traditionally, code must be split into onActivityResult and onRequestPermissionsResult.
  • Never have to deal with request code again, they are auto-generated.

Download

repositories {
    google()
    jcenter()
}

dependencies {
    compile 'com.hendraanggrian.appcompat:dispatcher:0.1'
}

Usage

Start activity for result from Activity, Fragment, or support Fragment.

startActivity(Intent(Intent.ACTION_GET_CONTENT).setType("image/*")) { resultCode, data ->
    if (resultCode == Activity.RESULT_OK) {
        val uri = data.getData()
        imageView.setImageUri(uri)   
    }
}


override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)
    Dispatcher.onActivityResult(this, requestCode, resultCode, data)
}

Request permission from Activity, Fragment, or support Fragment.

requestPermissions(Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE) { granted ->
    if (granted) {
        // do some shit   
    }
}


override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults)
    Dispatcher.onRequestPermissionsResult(this, requestCode, grantResults)
}

License

Copyright 2017 Hendra Anggrian

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.