Skip to content

Commit

Permalink
path from uri
Browse files Browse the repository at this point in the history
  • Loading branch information
CraZyLegenD committed Apr 11, 2019
1 parent 0d0e9cf commit ed7aa8a
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import android.content.ContentResolver
import android.content.Context
import android.database.Cursor
import android.net.Uri
import android.provider.MediaStore
import android.provider.OpenableColumns
import android.webkit.MimeTypeMap
import java.io.File
import java.lang.Exception


/**
Expand Down Expand Up @@ -92,3 +94,22 @@ val Uri.isTelephoneLink: Boolean

val Uri.isMailToLink: Boolean
get() = toString().startsWith("mailto:")

fun Context.getPathFromURI(contentUri: Uri): String? {
var res: String? = null
val proj = arrayOf(MediaStore.Images.Media.DATA)
val cursor = contentResolver.query(contentUri, proj, null, null, null)
try {
cursor?.apply {
if (cursor.moveToFirst()) {
val column_index = getColumnIndexOrThrow(MediaStore.Images.Media.DATA)
res = column_index.let { cursor.getString(it) }
}
}
} catch (e: Exception) {
e.printStackTrace()
} finally {
cursor?.close()
}
return res
}

0 comments on commit ed7aa8a

Please sign in to comment.