Wednesday, 23 May 2018

Android Runtime Permission with MyPermission Library in Kotlin

Android run time permission with MyPermission Library in Kotlin .
You can get Code from github DOWNLOAD

I am writing below Main Activity Code to have Access Permisssion

MainActivity.java
import android.Manifest
import android.os.Bundle
import com.stacklearning.mypermissionlibrary.MyPermission
import com.stacklearning.mypermissionlibrary.onPermisssionResult
class MainActivity : MyPermission() , onPermisssionResult {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        var permissionList = ArrayList<String>()
        permissionList.add( Manifest.permission.CAMERA)
        permissionList.add( Manifest.permission.WRITE_EXTERNAL_STORAGE)
        setPermission(this,permissionList,this)
    }
    override fun onPermissionGranted() {
        // open camera() and ...
        // ... etc what you want to do as per permission
    }
}


Here, We extend MainActivity from MyPermission() and Implement onPermissionResult
and we have to override onPermissionGranted() method .   to proceed with our code .

we have to pass PermissionList, like if we need camea permission, External Storage Permission and any other . Just pass this list to function   setPermission(this,permissionList,this) .


 If any problem in implementation, Please comment .