如何在Chrome瀏覽器中打開位於我的應用程序數據中的html頁面?對於我使用以下代碼的默認瀏覽器 -在Chrome瀏覽器中打開html頁面
Intent browserIntent = new Intent(Intent.ACTION_VIEW);
browserIntent.setData(Uri.fromFile(file));
browserIntent.setType("text/html");
browserIntent.setClassName("com.android.browser",
"com.android.browser.BrowserActivity");
browserIntent.addCategory(Intent.CATEGORY_BROWSABLE);
browserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
browserIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
browserIntent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
startActivity(browserIntent);
但是,此代碼不適用於Chrome瀏覽器。我怎樣才能在Chrome瀏覽器中打開相同的HTML頁面。
在此先感謝
刪除行setClassName ..您正在指定一些特定的活動,可能在某些設備上不存在。如果刪除該行的OS會爲你展示選擇哪個瀏覽器(或其他任何處理的text/html)與 – dymmeh
來查看文件的選項,但我想在Chrome中,而不要求用戶打開。什麼類的名稱使用鉻,以便我直接將該名稱放在那個地方。看看這個鏈接 - http://stackoverflow.com/questions/12013416/is-there-any-way-in-android-to-force-open-a-link-to-open-in-chrome我也使用這個,但它不起作用 –
嘗試setClassName(「com.android.chrome」,「com.android.chrome.Main」);不要忘記,如果用戶沒有安裝chrome,你的意圖會崩潰/失敗。這是不好的做法。 – dymmeh