1.作为演示,如下图所示,在界面中的链接按钮,目标是点击链接按钮调用手机浏览器打开特定的网站,首先建立响应方法:
link.setOnClickListener(buttonListener);
//....
此外需要响应方法:
case R.id.imageButton1:
link();
break;
2.在工程适当部分添加如下代码:
//press @link button and open brower to www.yiban.cn
private void link() {
// TODO Auto-generated method stub
String url = "http://www.webadress.cn"; // web address
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);
}
3.导入相应类:String、Content、Uri等,编译无错后运行测试,可以发现触发事件发生时就可以调用手机浏览器打开特定网页,示例中网址可以替换成你需要的网址!运行后效果如下所示:
调用默认浏览器
Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
Uri content_url = Uri.parse("此处填链接");
intent.setData(content_url);
startActivity(intent);
其他浏览器
Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
Uri content_url = Uri.parse("此处填链接");
intent.setData(content_url);
intent.setClassName("com.android.browser","com.android.browser.BrowserActivity"); startActivity(intent);
uc浏览器":"com.uc.browser", "com.uc.browser.ActivityUpdate“
opera:"com.opera.mini.android", "com.opera.mini.android.Browser"
qq浏览器:"com.tencent.mtt", "com.tencent.mtt.MainActivity"