Chrome user tab is automatically disabled if the Chrome browser is disabled by the user on his device

I'm trying to open pdf filein chrome custom tab, it works fine using this code

CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(this, Uri.parse("https://docs.google.com/viewerng/viewer?url=" +pdflink));

But the problem is that if the user has disabled chrome from the application settings, and it will not work for another browser. So how can I open it in the chrome custom tab if it is disabled.

Thanks in advance.

this is the exception that appears in the logarithm.

 Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=https://docs.google.com/... (has extras) }
+4
source share
2 answers

Try the following:

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
}
+5
source

Handle your exception as shown below.

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
}

EDIT

, .

startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS), 0);

REASON , SO. CommonsWare

Chrome , .

, Chrome Android. Google , Chrome.

+1

Source: https://habr.com/ru/post/1683217/


All Articles