簡體   English   中英

在 android 中,如何在不彈出“選擇瀏覽器”列表的情況下強制使用特定瀏覽器打開 URI?

[英]In android, How can I force open a URI using a specific browser, without popping up the 'choose browser' list?

我的 android 設備上有多個瀏覽器。 我可以使用以下代碼使用默認的 android 瀏覽器打開一個 URI:

    String packageName = "com.android.browser";  
    String className = "com.android.browser.BrowserActivity";  
    Intent internetIntent = new Intent(Intent.ACTION_VIEW); 
    internetIntent.addCategory(Intent.CATEGORY_LAUNCHER);  
    internetIntent.setClassName(packageName, className);  
    startActivity(internetIntent); 

我如何使用安裝在我的設備上的指定瀏覽器來完成相同的操作,比如 Opera。

非常感謝。

您需要將 packageName 和 className 設置為瀏覽器活動的 package 和 class 名稱。

例如,對於 Opera Mini,您需要執行以下操作:

String packageName = "com.opera.mini.android";
String className = "com.opera.mini.android.Browser";
Intent internetIntent = new Intent(Intent.ACTION_VIEW);
internetIntent.addCategory(Intent.CATEGORY_LAUNCHER);
internetIntent.setClassName(packageName, className);
startActivity(internetIntent);

對於其他瀏覽器,您可以通過執行以下操作找到 package 和 class 名稱:

  • 將 android 手機連接到電腦
  • 打開 Android Logcat
  • 從手機啟動瀏覽器

在 Android Logcat 中,您將看到如下內容:

07-22 14:06:14.662: INFO/ActivityManager(148): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.opera.mini.android/.Browser }

class 名稱將顯示在“cmp”屬性中:cmp=com.opera.mini.android/.Browser

In this case, the package name is com.opera.mini.android and the class name is com.opera.mini.android.Browser.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM