How To Open An URL In Android’s Web Browser
How To Open An URL In Android’s Web Browser
以下核心代码片断,将展现使用“android.content.Intent” 打开一个指定的 URL。
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://www.v2ex.com"));
startActivity(intent);
}
});
完整的代码,可参考以前的博文:http://blog.csdn.net/xiaowanggedege/article/details/9396961
再来一个例子:
How can I open a URL in Android's web browser from my application?
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
startActivity(browserIntent);
因为经常省略http://,所以以下代码也是经常用到:
if (!url.startsWith("http://") && !url.startsWith("https://"))
url = "http://" + url;
==================================================================
参考文献:

浙公网安备 33010602011771号