我是 Android 新手,我想创建一个 Intent 来查看谷歌网站。我的字符串声明如下:
static private final String URL = "http://www.google.com";
和我的 Intent :
Intent browserIntent = new Intent(Intent.ACTION_VIEW);
browserIntent.setData(Uri.parse("geo:+URL"));
startActivity(browserIntent);
此代码在 Eclipse 中没有显示错误,但我认为它可能是错误的。
在尝试连接 2 个字符串时,您没有正确构建 Uri,请使用:
String s = "I'm a string variable";
String concatenated = s + " and I'm another String variable";
现在concatenated的内容是
I'm a string variable and I'm another String variable
如果你这样做:
String concatenated = "s + and I'm another String variable";
concatenated的内容是
s + and I'm another String variable
其次,您为什么要使用地理 Uri?这是为了查看位置。要查看网站,只需使用 URL(不要忘记“http://”部分):
String URL = "http://www.google.com";
browserIntent.setData(Uri.parse(URL));
我是一名优秀的程序员,十分优秀!