其他分享
首页 > 其他分享> > android – 如果用户在其设备中禁用了Chrome浏览器,则Chrome自定义标签会崩溃

android – 如果用户在其设备中禁用了Chrome浏览器,则Chrome自定义标签会崩溃

作者:互联网

我试图在chrome自定义选项卡中打开pdf文件,使用此代码可以正常工作

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
}

标签:chrome-custom-tabs,android,pdf,browser
来源: https://codeday.me/bug/20190828/1750978.html