我们可以使用移动设备上的浏览器打开下载的PDF文件吗?

时间:2019-06-19 12:43:23

标签: pdf android-intent mobile-browser

我正在android应用程序中生成PDF,并在将其下载到设备后立即将其打开。

我使用下面的代码打开PDF,并使用已经安装的PDF查看器打开了它。

            Intent intent = new Intent(Intent.ACTION_VIEW);       
            Uri uri = FileProvider.getUriForFile (context, "com.example.android.fileprovider" , file);  
            intent.setDataAndType(uri, "application/pdf");
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);  
            startActivity(intent);

现在,我想使用浏览器打开PDF,并尝试了以下代码

        Intent intent = new Intent(Intent.ACTION_VIEW);
        Uri uri = FileProvider.getUriForFile(getApplicationContext(),"com.example.android.fileprovider", file);
        intent.setDataAndType(uri, "application/pdf");
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setPackage("com.android.chrome");   
        startActivity(intent);

但是这给了我一个错误,即没有活动可以处理上述意图。

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=content://com.example.android.fileprovider/external_files/Download/Login Page20190619_174738.pdf typ=application/pdf flg=0x10000001 pkg=com.android.chrome }

我在互联网上进行搜索,但找不到与我的要求有关的任何内容。由于无法使用移动浏览器打开外部存储上的PDF,因此我怀疑它们是否支持PDF查看,但是我确定Web浏览器确实支持。

有人可以澄清一下移动浏览器是否真的支持PDF查看吗?如果是这样,如何从另一个应用程序在浏览器中打开PDF?如果不是这样,对于不熟悉技术的用户来说,显示PDF的最佳方法是什么?

0 个答案:

没有答案
相关问题