2011-02-08 15 views
65

Devo aprire un URL sul pulsante Click del pulsante OK in una vista. Qualcuno può dire come fare questo?aprire un URL al clic del pulsante ok in Android

+1

Usa [HttpURLConnection] (http: // sviluppatore .android.com/riferimento/java/net/HttpURLConnection.html). –

+8

public void openWebURL (String inURL) { Intent browse = new Intent (Intent.ACTION_VIEW, Uri.parse (inURL)); startActivity (sfoglia); } – User

+0

è questo il modo giusto harry? – User

risposta

180

Su Button evento click scrivere questo:

Uri uri = Uri.parse("http://www.google.com"); // missing 'http://' will cause crashed 
Intent intent = new Intent(Intent.ACTION_VIEW, uri); 
startActivity(intent); 

che aprire il tuo URL.

+1

OPPURE 'startActivity (nuovo Intent (Intent.ACTION_VIEW, Uri.parse (" http://www.google.com ")) ' –

2
Button imageLogo = (Button)findViewById(R.id.iv_logo); 
    imageLogo.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      String url = "http://www.gobloggerslive.com"; 

      Intent i = new Intent(Intent.ACTION_VIEW); 
      i.setData(Uri.parse(url)); 
      startActivity(i); 
     } 
    }); 
0

È possibile utilizzare il seguente metodo, che avrà l'URL di destinazione come l'unico ingresso (Non dimenticare http: //)

void GoToURL(String url){ 
    Uri uri = Uri.parse(url); 
    Intent intent= new Intent(Intent.ACTION_VIEW,uri); 
    startActivity(intent); 
} 
Problemi correlati