Android从对话框启动浏览器

时间:2011-04-22 10:44:45

标签: android android-activity dialog itemizedoverlay

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

这是我的代码:

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,但突然之间不适合我..

感谢

2 个答案:

答案 0 :(得分:3)

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

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

答案 1 :(得分:0)

您的AInfos[5]很可能不是一个合适的网址。对http://www.google.com之类的网址进行硬编码,然后查看它是否有效。同时打印AInfos[5]包含的内容。