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 



再来一个例子:

 


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;


==================================================================
参考文献:

 

 

 

相关文章:

  • 2022-12-23
  • 2021-07-08
  • 2022-03-07
  • 2021-12-23
  • 2021-10-27
  • 2022-12-23
  • 2021-09-30
猜你喜欢
  • 2022-12-23
  • 2021-10-22
  • 2021-11-01
  • 2021-05-25
  • 2022-12-23
  • 2021-06-08
相关资源
相似解决方案