Android 从对话框启动浏览器

标签 android android-activity dialog itemizedoverlay

我有一个显示逐项覆盖的 map View ,每个 onTap 事件都会显示一个对话框,其中包含有关旅行社的信息和三个按钮,其中一个按钮应该在浏览器中打开旅行社网站,但是当我单击我得到的按钮:没有找到处理 Intent 的 Activity 。

这是我的代码:

protected boolean onTap(int i){
float[] results = new float[1];
        Location.distanceBetween(decdegrees(appState.getMyLocation().getLatitudeE6()), decdegrees(appState.getMyLocation().getLongitudeE6()), decdegrees(points.get(i).getPoint().getLatitudeE6()), decdegrees(points.get(i).getPoint().getLongitudeE6()), results);
        float distance = results[0]/1000;
        DecimalFormat maxDigitsFormatter = new DecimalFormat("#.#");
        String infos=points.get(i).getSnippet() + "#" + String.valueOf(maxDigitsFormatter.format(distance));
        final String [] AInfos = infos.split("#");

        final Dialog ADialog = new Dialog(c);
        ADialog.setContentView(R.layout.travelagency);

        TextView txtAgence = (TextView)ADialog.findViewById(R.id.txtAgence);
        TextView txtAddress = (TextView)ADialog.findViewById(R.id.txtAddress);
        TextView txtDistance = (TextView)ADialog.findViewById(R.id.txtDistance);
        TextView txtFax = (TextView)ADialog.findViewById(R.id.txtFax);
        Button btnCall = (Button)ADialog.findViewById(R.id.btnCall);
        Button btnWebSite = (Button)ADialog.findViewById(R.id.btnWebSite);
        Button btnCancel = (Button)ADialog.findViewById(R.id.btnCancel);

        ADialog.setTitle(AInfos[0]);
        btnCall.setText("Appeler : " + AInfos[2]);
        txtAgence.setText(AInfos[1]);
        txtDistance.setText("Approximativement à : " +AInfos[6] + " Km");
        txtAddress.setText("Adresse : " + AInfos[3]);
        txtFax.setText("Fax : " + AInfos[4]);
        ADialog.show();

        btnCancel.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                ADialog.dismiss();
            }
        });

        btnWebSite.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                Intent myIntent = new Intent(Intent.ACTION_VIEW,Uri.parse(AInfos[5]));
                v.getContext().startActivity(myIntent);
            }
        });

        return (true);
    }

我找到了例子herehere但突然对我不起作用..

谢谢

最佳答案

这将创建在默认浏览器中打开网页的正确 Intent :

Uri url = Uri.parse("http://www.someUrl.com");
        Intent intent = new Intent(Intent.ACTION_VIEW, url);
        startActivity(intent);

关于Android 从对话框启动浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5754632/

相关文章:

java - Android 应用程序的 HTTP 接口(interface)

android - 如何在 VR 视频上叠加 "play button"?

Android - fragment 是 "transparent",我可以点击它

android - 自定义样式的 AlertDialog 的样式属性

android - 让 Activity 始终在堆栈顶部,还是在恶意应用启动 Activity 时保持焦点?

Android:服务如何在后面显示的堆栈中没有旧 Activity 的情况下启动 Activity

android - 如何让adb server 不响应?

android - 分享 API 不与 Facebook 分享消息

android - Android 中的 WIN DEATH 错误?

android - rxjava android retryWhen 在上次尝试时没有调用 onError