![](/img/trans.png)
[英]How to load chrome custom tab when multiple browsers installed in the device and user has set different browser as default instead of chrome browser?
[英]Chrome custom tab crashes if chrome browser is disabled by the user in his device
我試圖在chrome custom tab
打開pdf file
,使用此代碼可以正常工作
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(this, Uri.parse("https://docs.google.com/viewerng/viewer?url=" +pdflink));
但問題是,如果用戶已從應用程序設置中禁用了Chrome,並且沒有其他瀏覽器崩潰。 那么如果禁用它,我如何在chrome自定義選項卡中打開它。
提前致謝。
這是logcat中出現的異常。
Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=https://docs.google.com/... (has extras) }
試試這個:
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.build();
try {
customTabsIntent.launchUrl(this, Uri.parse("https://docs.google.com/viewerng/viewer?url=" +pdflink));
}
catch (ActivityNotFoundException e)
{
// display message to user
}
處理您的異常,如下所示
try{
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(this, Uri.parse("https://docs.google.com/viewerng/viewer?url=" +pdflink));
}catch(ActivityNotFoundException e){
// Handle your exception
}
編輯
如果用戶已將其禁用,則可以要求用戶從設置中啟用它。
打開手機設置的代碼
startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS), 0);
這背后的原因 ,可以從這篇SO帖子中輕松搜索到。 由CommonsWare撰寫
Chrome似乎無法導出該活動,因此第三方應用無法啟動它。
即使他們這樣做,這種行為也可能因Chrome for Android版本而異。 Google不會記錄或支持從任何商業應用訪問此類活動,更不用說Chrome了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.