add a helper function for retrieving file content uri

This commit is contained in:
tibbi 2017-10-26 20:40:24 +02:00
parent b41e2fca99
commit 28dd99563b

View file

@ -12,6 +12,7 @@ import android.os.Looper
import android.provider.BaseColumns
import android.provider.MediaStore
import android.support.v4.content.ContextCompat
import android.support.v4.content.FileProvider
import android.support.v7.app.AlertDialog
import android.view.LayoutInflater
import android.view.View
@ -24,6 +25,7 @@ import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.views.*
import kotlinx.android.synthetic.main.dialog_title.view.*
import java.io.File
fun Context.isOnMainThread() = Looper.myLooper() == Looper.getMainLooper()
fun Context.getSharedPrefs() = getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE)
@ -159,3 +161,11 @@ fun Context.getPermissionString(id: Int) = when (id) {
PERMISSION_WRITE_CALENDAR -> Manifest.permission.WRITE_CALENDAR
else -> ""
}
fun Context.getFileContentUri(file: File, applicationId: String): Uri {
return if (isNougatPlus()) {
FileProvider.getUriForFile(this, "$applicationId.provider", file)
} else {
Uri.fromFile(file)
}
}