URL详解

2017-07-07  本文已影响0人  crazydane
一个完整的URL结构如下

scheme:[//[user:password@]host[:port]][/]path[?query][#fragment]
方框内的是可选部分。

打开网页
String urlAsString = "http://www.udacity.com";
Uri webpage = Uri.parse(urlAsString );
Intent intent = new Intent(Intent.ACTION_VIEW, webpage);
if (intent.resolveActivity(getPackageManager()) != null) {
      startActivity(intent);
}
打开地图
String addressString = "1600 Amphitheatre Parkway, CA";
Uri.Builder builder = new Uri.Builder();
builder.scheme("geo")
        .path("0,0")
        .query(addressString);
Uri addressUri = builder.build();
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(addressUri );
if (intent.resolveActivity(getPackageManager()) != null) {
      startActivity(intent);
}
上一篇 下一篇

猜你喜欢

热点阅读