[英]Give the option to always choose a browser to open a link
有沒有辦法讓用戶始終選擇應打開特定鏈接的應用程序(瀏覽器)? 類似於如果用戶尚未選擇默認程序會發生的情況。
我的密碼
Intent intent = new Intent(Intent.ACTION_VIEW);
forumintent.setData(Uri.parse(url));
startActivity(intent);
以下方法適用於所有隱式意圖-不限於您關於瀏覽器的問題。
通常。 當您發出隱式意圖(例如ACTION_VIEW
)時,主機Android設備將檢查是否存在默認應用程序來處理該意圖。 如果有默認應用程序,則默認情況下,android將自動重定向到該應用程序。
但是,您可以為隱式意圖強制應用選擇器。 為此,您需要使用Intent.createChooser()
方法。 請參閱以下示例:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url)); // only used based on your example.
String title = "Select a browser";
// Create intent to show the chooser dialog
Intent chooser = Intent.createChooser(intent, title);
// Verify the original intent will resolve to at least one activity
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(chooser);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.