用于查看URL的隐含意图

use*_*769 3 android

我是Android新手,我想创建一个Intent来查看谷歌网站.我的String声明如下:

static private final String URL = "http://www.google.com";
Run Code Online (Sandbox Code Playgroud)

和我的意图:

Intent browserIntent = new Intent(Intent.ACTION_VIEW);
browserIntent.setData(Uri.parse("geo:+URL"));
startActivity(browserIntent);
Run Code Online (Sandbox Code Playgroud)

此代码在Eclipse中没有显示错误,但我认为这可能是错误的.

2De*_*Dee 6

在尝试连接2个String时,你没有正确构建你的Uri,请使用:

String s = "I'm a string variable";

String concatenated = s + " and I'm another String variable";
Run Code Online (Sandbox Code Playgroud)

现在连接的内容是

我是一个字符串变量,我是另一个String变量

如果你这样做:

String concatenated = "s + and I'm another String variable";
Run Code Online (Sandbox Code Playgroud)

连接的内容是

s +和我是另一个String变量

其次,你为什么要使用地理Uri?这是用于查看位置.要查看网站,只需使用URL(不要忘记"http://"部分):

String URL = "http://www.google.com";
browserIntent.setData(Uri.parse(URL));
Run Code Online (Sandbox Code Playgroud)