在 Android 應用中調用系統瀏覽器打開指定 URL,核心代碼僅需 5 行,利用 Intent.ACTION_VIEW 隱式意圖實現。
// 按鈕點擊監聽
link.setOnClickListener(buttonListener);
// 響應方法
case R.id.imageButton1:
link();
break;
// 打開網頁方法
private void link() {
String url = "https://www.webadress.cn"; // 目標網址
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);
}
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.widget.Button;
點擊按鈕後,系統彈出瀏覽器選擇器(或直接跳轉默認瀏覽器)加載目標頁面。可將 URL 替換為任意合法鏈接(http/https/tel/mailto 等)。

擴展: 若需指定瀏覽器包名,可用 intent.setPackage("com.android.chrome");若需在 WebView 內打開,則另行實現。