How can I convert a String to a Uri in Kotlin instead of java (Android)?
val Uri_string = "/sdcard/example.jpg"
Uri_string = ???;
val uri = Uri.parse(Uri_string)
or
val fileName = "example.jpg"
val path = "${Environment.getExternalStorageDirectory()}/$fileName"
val file = File(path);
val uri = Uri.fromFile(file);
If you are using Android KTX you can also parse this way:
val uri_string = "/sdcard/example.jpg"
val uri = uri_string.toUri()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With