jkwiecien / EasyImage

Library for picking pictures from gallery or camera
1.75k stars 303 forks source link

Android Q New API to get and save images #202

Open Beatis opened 4 years ago

Beatis commented 4 years ago

I would like to ask, will you upgrade your library for new API where we dont have access to save our images in public storage, like it happens now, instead we have to use temporary files for saving data about captured images and write it into MediaStore?

DarkZaid commented 4 years ago

My problem exactly,my head hurts.lol.Did u find the solution?

Beatis commented 4 years ago

My problem exactly,my head hurts.lol.Did u find the solution?

I just save file manually with this code.

fun handleActivityResult(requestCode: Int, resultCode: Int, data: Intent?, func: (bitmap: Bitmap) -> Unit) {
        imageManager.handleActivityResult(
            requestCode,
            resultCode,
            data,
            context as Activity,
            object : DefaultCallback() {
                override fun onMediaFilesPicked(imageFiles: Array<MediaFile>, source: MediaSource) {
                    imageFiles[0].also {
                        savePublicImage(it.file)
                    }
                }

            })
    }
private fun savePublicImage(file: File) {
        val values = ContentValues()
        values.put(MediaStore.Images.Media.TITLE, context.getString(R.string.app_name))
        values.put(MediaStore.Images.Media.MIME_TYPE, "image/*")
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
            values.put(
                MediaStore.Images.Media.RELATIVE_PATH,
                "DCIM/${context.getString(R.string.app_name)}"
            )
        }
        val item =
            context.contentResolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values)
        item?.let { uri ->
            context.contentResolver.openFileDescriptor(uri, "w", null).use { pfd ->
                pfd?.let {
                    val output = FileOutputStream(it.fileDescriptor)
                    output.write(file.readBytes())
                    output.close()
                }
            }
        }
    }
DarkZaid commented 4 years ago

Thank you but i don't know how to code in Kotlin