Consider implementing an app, that lets users pick images taken with a camera from Gallery, and then use those pics on the app.
Project settings are:
targetSdk=34, compileSdk=34, minSdk=22
Using MediaStore API, I can launch the picker using:
startActivityForResult(Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI) ,1);
and then acquire a picture in onActivityResult()
override fun onActivityResult(requestCode: Int, resultCode: Int, intent: Intent?) {
super.onActivityResult(requestCode, resultCode, intent)
val uri = intent!!.data!!
val inputStream = contentResolver.openInputStream(uri)!!
val bitmapBytes = inputStream.readBytes()
val bitmap = BitmapFactory.decodeByteArray(bitmapBytes, 0, bitmapBytes.size)
}
Question 1:
What permissions are needed to produce Bitmap? I’m reading specs that READ_EXTERNAL_STORAGE would be needed. But the code works without any permission in SDK 34-24, and starts only requiring READ_EXTERNAL_STORAGE on <= SDK 23.
Question 2:
Why I’m not needing READ_MEDIA_IMAGES on >= SDK 33? As it states on another specs, implementation needs that permission to read images other app produced on SDK 33 onwards.
Question 3:
What would be the advantage of using PhotoPicker API (instead of MediaStore)?