2011-04-22 54 views
2

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

这里是我的代码:

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但suddently不是为我工作..

感谢

回答

3

这将创建正确的意图,打开一个网页默认浏览器:

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

是我没有看到它的代码,“btnWebSite.setOnClickListener(新OnClickListener(){ 公共无效的onClick(视图v){ 意图myIntent =新意图(Intent.ACTION_VIEW,Uri.parse(AInfos [5]) ); v.getContext()。startActivity(myIntent); } });'如果我删除v.getContext它会导致其他错误 – Houssem 2011-04-22 10:51:36

+0

调试应用程序,并确保AInfos [5]是一个网址 – 2011-04-22 10:55:28

+0

你是对的AInfos [5]是空值,所以当我通过正确的网址,它的作品,但与此:v.getContext()。startActivity(myIntent)非常感谢你 – Houssem 2011-04-22 11:07:48

0

很可能你的AInfos[5]不是一个合适的网址。对http://www.google.com这样的网址进行硬编码,并确定它是否首先运行。还打印什么AInfos[5]包含。

+0

谢谢这是我的错误 – Houssem 2011-04-22 22:03:55