2011-02-08 47 views
65

Tôi phải mở URL trên Click của OK Nút trong chế độ xem. Ai đó có thể nói làm thế nào để làm điều này?mở url trên nhấp vào nút ok trong android

+1

Sử dụng [HttpUrlConnection] (http: // nhà phát triển .android.com/reference/java/net/HttpURLConnection.html). –

+8

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

+0

đây có phải là cách đúng đắn không? – User

Trả lời

180

On Button sự kiện click viết này:

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

mở URL của bạn.

+1

HOẶC 'startActivity (Ý định mới (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

Bạn có thể sử dụng phương pháp dưới đây, mà sẽ lấy URL mục tiêu của bạn là đầu vào chỉ (Đừng quên http: //)

void GoToURL(String url){ 
    Uri uri = Uri.parse(url); 
    Intent intent= new Intent(Intent.ACTION_VIEW,uri); 
    startActivity(intent); 
} 
Các vấn đề liên quan