如何从我的应用程序在 Android 的 Web 浏览器中打开 URL? [英] How can I open a URL in Android's web browser from my application?
本文介绍了如何从我的应用程序在 Android 的 Web 浏览器中打开 URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在内置网络浏览器中而不是在我的应用程序中通过代码打开 URL?
How to open an URL from code in the built-in web browser rather than within my application?
我试过这个:
try {
Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(download_link));
startActivity(myIntent);
} catch (ActivityNotFoundException e) {
Toast.makeText(this, "No application can handle this request."
+ " Please install a webbrowser", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
但我有一个例外:
No activity found to handle Intent{action=android.intent.action.VIEW data =www.google.com
推荐答案
试试这个:
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
startActivity(browserIntent);
这对我来说很好.
至于缺少的http://",我会这样做:
As for the missing "http://" I'd just do something like this:
if (!url.startsWith("http://") && !url.startsWith("https://"))
url = "http://" + url;
我也可能会预先填充用户正在使用http://"键入 URL 的 EditText.
I would also probably pre-populate your EditText that the user is typing a URL in with "http://".
这篇关于如何从我的应用程序在 Android 的 Web 浏览器中打开 URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文