2011-04-22 20 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