一個完整的URL結(jié)構(gòu)如下
scheme:[//[user:password@]host[:port]][/]path[?query][#fragment]
方框內(nèi)的是可選部分悼瓮。
- scheme : 描述了我們指向的資源的類型艘策,web上常見的scheme類型包括HTTP和HTTPS牡辽,mailto跛溉,F(xiàn)TP佛嬉,文件和geo但還有很多其他的镰惦。mailto是一種不要求authority部分只用路徑便可以導(dǎo)航影晓,路徑是你的電子郵件收件人镰吵。
- user : password@用戶的登錄名以及密碼
- host : 可以是域名或者ip地址
- port : 沒有特殊指示的話一般是80
- path : 資源路徑
- query : 它通常使用鍵值對來制定數(shù)據(jù),但也不是必須的
- fragment : 只是路徑資源將使用的輔助數(shù)據(jù)
打開網(wǎng)頁
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);
}