【发布时间】:2011-09-10 18:18:34
【问题描述】:
可能重复:
How can I open a URL in Android’s web browser from my application?
我一直在尝试找出如何创建在指定浏览器中打开指定 URL 的意图。浏览器可能并不总是默认的。 但是我做不到。
【问题讨论】:
标签: android
可能重复:
How can I open a URL in Android’s web browser from my application?
我一直在尝试找出如何创建在指定浏览器中打开指定 URL 的意图。浏览器可能并不总是默认的。 但是我做不到。
【问题讨论】:
标签: android
试试这个:
String url = "your URL";
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(browserIntent);
【讨论】:
使用 Intent.ACTION_VIEW 常量作为 Intent 操作,使用 url 作为数据。
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
activity.startActivity(intent);
请注意,该 URL 必须是完整的 URL(以 http:// 或 https:// 开头),因此请检查您的代码,确保该 URL 不是诸如 www.google.com 之类的短格式(如果它是用户)-已定义。
【讨论】:
你可以使用其中任何一个,也可以阅读Link
Intent browserIntent = new Intent("android.intent.action.VIEW", Uri.parse("http://www.google.com"));
startActivity(browserIntent);
或
String url = "http://www.example.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url)); startActivity(i);
【讨论】: