Convert String to Uri Convert String to Uri android android

Convert String to Uri


You can use the parse static method from Uri

//...import android.net.Uri;//...Uri myUri = Uri.parse("http://stackoverflow.com")


I am just using the java.net package.Here you can do the following:

...import java.net.URI;...String myUrl = "http://stackoverflow.com";URI myURI = new URI(myUrl);


If you are using Kotlin and Kotlin android extensions, then there is a beautiful way of doing this.

val uri = myUriString.toUri()

To add Kotlin extensions (KTX) to your project add the following to your app module's build.gradle

  repositories {    google()}dependencies {    implementation 'androidx.core:core-ktx:1.0.0-rc01'}