我必须在视图中点击OK
按钮打开一个URL。有人可以告诉如何做到这一点?在android中点击确定按钮打开一个url
65
A
回答
180
在Button
click事件写:
Uri uri = Uri.parse("http://www.google.com"); // missing 'http://' will cause crashed
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
打开了您的网址。
2
Button imageLogo = (Button)findViewById(R.id.iv_logo);
imageLogo.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String url = "http://www.gobloggerslive.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
}
});
0
您可以使用下面的方法,这将需要你的目标URL作为唯一的输入(不要忘了HTTP://)
void GoToURL(String url){
Uri uri = Uri.parse(url);
Intent intent= new Intent(Intent.ACTION_VIEW,uri);
startActivity(intent);
}
使用[HttpURLConnection类](HTTP://开发商.android.com /参考/ JAVA /净/ HttpURLConnection.html)。 – 2011-02-08 06:32:45
public void openWebURL(String inURL){ Intent browse = new Intent(Intent.ACTION_VIEW,Uri.parse(inURL)); startActivity(browse); } – User 2011-02-08 06:34:17