我想use intent.setData(Uri uri)传递从URL获得的数据.为了做到这一点,我需要能够从URL创建一个Uri(或者从我从URL读取的byte [],或者ByteArrayInputStream我从中创建的byte[]等等).但是,我无法弄清楚应该怎么做.
那么,无论如何从URL获取的数据创建Uri而不首先将数据写入本地文件?
Buh*_*ndi 43
使用URL.toURI()(Android doc)方法.
例:
URL url = new URL("http://www.google.com"); //Some instantiated URL object
URI uri = url.toURI();
Run Code Online (Sandbox Code Playgroud)
确保处理相关的异常,例如URISyntaxException.
小智 11
我想你的答案可以在这里找到..
Uri.Builder.build() 使用普通的URL工作得很好,但它支持端口号失败.
我发现使其支持端口号的最简单方法是首先解析给定的URL,然后使用它.
Uri.Builder b = Uri.parse("http://www.yoursite.com:12345").buildUpon();
b.path("/path/to/something/");
b.appendQueryParameter("arg1", String.valueOf(42));
if (username != "") {
b.appendQueryParameter("username", username);
}
String url = b.build().toString();
Run Code Online (Sandbox Code Playgroud)
资料来源:http://twigstechtips.blogspot.com/2011/01/android-create-url-using.html
| 归档时间: |
|
| 查看次数: |
75410 次 |
| 最近记录: |