簡體   English   中英

如果用戶在其設備中禁用了Chrome瀏覽器,則Chrome自定義標簽會崩潰

[英]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.

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