Hey guys I have a question. When I select an image...
# android
h
Hey guys I have a question. When I select an image from the Document, its uri looks like this:
[<content://com.android.providers.media.documents/document/image%3A38>]
However, when I take a photo and store it in MediaStore.Images, then its uri looks like this:
[<content://media/external/images/media/51>]
. Is there anyway that I get a uri like the first uri? [code in the comment]
stackoverflow 6
Copy code
fun dispatchTakePictureIntent(activity: Activity) {
    Intent(MediaStore.ACTION_IMAGE_CAPTURE).also { takePictureIntent ->
        val camIntent = takePictureIntent.resolveActivity(activity.packageManager)
        camIntent?.also {
            val timeStamp: String = SimpleDateFormat("yyyyMMdd_HHmmss", Locale.CANADA).format(Date())
            val values = ContentValues()
            values.put(MediaStore.Images.Media.TITLE, "ATCO - $timeStamp")
            values.put(MediaStore.Images.Media.DESCRIPTION, "Deficiency picture.")
            activity.contentResolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values)?.let {
                takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, it)
                activity.startActivityForResult(takePictureIntent, REQUEST_CODE_IMAGE_CAPTURE)
            }
        }
    }
}
This is the easiest thing I could do to hack it 🙂
Copy code
val path = if (stringUri.contains("com.android.providers")) stringUri else {
        val fileName: String = stringUri.substring(stringUri.lastIndexOf("/") + 1, stringUri.length)
        "<content://com.android.providers.media.documents/document/image:$fileName>"
    }
a
Use
intent
based on your application id
file provider.