Read and Write permission for storage and gallery usage for marshmallow

后端 未结 6 2119
迷失自我
迷失自我 2021-01-01 22:08

I am developing an android app in which it is required to provide permission for Read and write external storage. My requirement is to select a picture from gallery and use

6条回答
  •  无人及你
    2021-01-01 22:33

    For writing a file in storage, First,need to add write permission in manifest.xml,

    Then, In Android 6, it contains a permission system for certain tasks. Each application can request the required permission on runtime. So let’s open Activity class add below code for requesting runtime permission.

    check your application has a runtime write permission using,

    override fun onRequestPermissionsResult(requestCode: Int,
        permissions: Array,
        grantResults: IntArray) {
    
        when(requestCode)  {
    
            100 -> {
                if (grantResults.size > 0 && permissions[0] == Manifest.permission.WRITE_EXTERNAL_STORAGE) {
                    if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    
                    }
                }
    
            }
        }
    
    }
    

提交回复
热议问题