poe*_*orn 713 android android-intent
我只是想知道如何启动一个Intent到手机的浏览器打开一个特定的URL并显示它.
有人可以给我一个提示吗?
aio*_*obe 1679
要打开URL /网站,请执行以下操作:
String url = "http://www.example.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
Run Code Online (Sandbox Code Playgroud)
来源:从应用程序内部在Android的Web浏览器中打开URL
小智 153
最短的版本.
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com")));
Run Code Online (Sandbox Code Playgroud)
Bak*_*kyt 83
在某些情况下,URL可能以"www"开头.在这种情况下,您将获得一个例外:
android.content.ActivityNotFoundException: No Activity found to handle Intent
Run Code Online (Sandbox Code Playgroud)
URL必须始终以"http://"或"https://"开头,因此我使用此剪辑代码:
if (!url.startsWith("https://") && !url.startsWith("http://")){
url = "http://" + url;
}
Intent openUrlIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(openUrlIntent);
Run Code Online (Sandbox Code Playgroud)
Jor*_*sys 44
String url = "https://www.stackoverflow.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
Run Code Online (Sandbox Code Playgroud)
Intent intent = new Intent(Intent.ACTION_VIEW).setData(Uri.parse("http://www.stackoverflow.com"));
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
要么
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.stackoverflow.com"));
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.stackoverflow.com")));
Run Code Online (Sandbox Code Playgroud)
有关Intent的更多信息
=)
Phi*_*hil 26
还有一种方法可以将coords直接传递给Google地图显示吗?
您可以使用地理 URI前缀:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("geo:" + latitude + "," + longitude));
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
Sat*_*aty 13
如果您的视图上显示了网址/ URL,并且您希望它使其可以访问并将用户指向特定网站您可以使用:
android:autoLink="web"
Run Code Online (Sandbox Code Playgroud)
同样,您可以使用autoLink的不同属性(电子邮件,电话,地图,全部)来完成您的任务......
小智 10
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
startActivity(browserIntent);
Run Code Online (Sandbox Code Playgroud)
小智 7
在代码中使用以下代码段
Intent newIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("https://www.google.co.in/?gws_rd=cr"));
startActivity(newIntent);
Run Code Online (Sandbox Code Playgroud)
使用此链接
http://developer.android.com/reference/android/content/Intent.html#ACTION_VIEW
| 归档时间: |
|
| 查看次数: |
575054 次 |
| 最近记录: |