/**
* 調用第三方瀏覽器打開
* @param context
* @param url 要瀏覽的資源地址
*/
public static void openBrowser(Context context,String url){
final Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
// 注意此處的判斷intent.resolveActivity()能夠返回顯示該Intent的Activity對應的組件名
// 官方解釋 : Name of the component implementing an activity that can display the intent
if (intent.resolveActivity(context.getPackageManager()) != null) {
final ComponentName componentName = intent.resolveActivity(context.getPackageManager());
// 打印Log ComponentName究竟是什麼
L.d("componentName = " + componentName.getClassName());
context.startActivity(Intent.createChooser(intent, "請選擇瀏覽器"));
} else {
Toast.makeText(context.getApplicationContext(), "請下載瀏覽器", Toast.LENGTH_SHORT).show();
}
}
---------------------
做者:風正吹
來源:CSDN
原文:https://blog.csdn.net/yingtian648/article/details/79128663/
版權聲明:本文爲博主原創文章,轉載請附上博文連接!瀏覽器