English 中文(简体)
• 如何创建海底。 Uri from a java.net. URL?
原标题:How to create a android.net.Uri from a java.net.URL?
  • 时间:2011-11-23 09:51:45
  •  标签:
  • java
  • android

我谨通过<代码>使用意图.setData(Uri uri)通过从URL获得的数据。 为此,我需要能够从URL(或从旁听)中建立一个Uri。 页: 1 ByteArrayInputStream 页: 1 然而,我无法说明应如何做到这一点。

So, is there anyway to create a Uri from data obtained from a URL without first writing the data to a local file?

问题回答

From How to create a Uri from a URL?

Uri uri =  Uri.parse( "http://www.facebook.com" );

注:在安内斯,Uri s与Java URI s不同。 在这里,如何避免使用硬编码拼法,同时,创建一条Uri,其途径部分仅包括http URL string encoded to RFC2396:

Sample Url String:

String thisUrl = "http://lapi.transitchicago.com/api/1.0/ttarrivals.aspx?key=[redacted]&mapid=value"

方法:

private Uri.Builder builder;
public Uri getUriFromUrl(String thisUrl) {
    URL url = new URL(thisUrl);
    builder =  new Uri.Builder()
                            .scheme(url.getProtocol())
                            .authority(url.getAuthority())
                            .appendPath(url.getPath());
    return builder.build();
}

为了处理询问,你需要将所描述的“url.get Query”(,,然后将这些资料输入建筑商。 附录。

try {
    uri = new URI(url.toString());
} catch (URISyntaxException e) {
}




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签