2

I've a mapview that displays an itemized overlay, and each onTap event shows a dialog with information about travel agency and three buttons, one of them is supposed to open the agency web site in the browser, but when i click the button i got : no activity found to handle Intent.

here's my code :

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);
    }

I found examples here and here but suddently not work for me..

thanks

Community
  • 1
  • 1
Houssem
  • 2,069
  • 3
  • 27
  • 42

2 Answers2

3

This will create the proper intent to open a web page in the default browser:

Uri url = Uri.parse("http://www.someUrl.com");
        Intent intent = new Intent(Intent.ACTION_VIEW, url);
        startActivity(intent);
Tom O
  • 1,780
  • 2
  • 20
  • 43
  • yes i did it see the code, 'btnWebSite.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent myIntent = new Intent(Intent.ACTION_VIEW,Uri.parse(AInfos[5])); v.getContext().startActivity(myIntent); } });' and if i remove v.getContext it causes an other error – Houssem Apr 22 '11 at 10:51
  • Debug the app and make sure that AInfos[5] is a Url – Tom O Apr 22 '11 at 10:55
  • you're right AInfos[5] was null value, so when i pass the right url, it works, but with this :v.getContext().startActivity(myIntent) thank you very much – Houssem Apr 22 '11 at 11:07
0

Most probably your AInfos[5] is not a proper url. Hard-code a url like http://www.google.com and see if it works first. Also print what AInfos[5] contains.

Rajath
  • 11,787
  • 7
  • 48
  • 62