How to create a android.net.Uri from a java.net.URL?

后端 未结 6 699
南方客
南方客 2020-12-15 04:21

I would like to use intent.setData(Uri uri) to pass data obtained from a URL. In order to do this, I need to be able to create a Uri from a URL (or from a byte

6条回答
  •  不思量自难忘°
    2020-12-15 04:45

    Use URL.toURI() (Android doc) method.

    Example:

    URL url = new URL("http://www.google.com"); //Some instantiated URL object
    URI uri = url.toURI();
    

    Make sure to handle relevant exception, such as URISyntaxException.

提交回复
热议问题