繁体   English   中英

在android studio上打开pdf文件并打开黑屏pdf

[英]Open pdf file on android studio and open a black screen pdf

模拟器。尝试打开存储在模拟器中并通过文件提供程序的pdf文件。 问题是pdf打开但内容为空(黑屏)。 谢谢!

            File item = new File("/storage/emulated/0/Download/theoretical_computer_science_cheat_sheet.pdf");
            Uri uri = FileProvider.getUriForFile(MainActivity.this[enter image description here][1],getApplicationContext().getPackageName() + ".share",item);
            //Uri uri = getUriForFile(getBaseContext(), getApplicationContext().getPackageName() + ".share",item);
            Intent intent = new Intent(Intent.ACTION_VIEW,uri);
            intent.setDataAndType(uri,"application/pdf");

            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
            try {
                getApplicationContext().startActivity(intent);
            } catch (ActivityNotFoundException e) {
                // Instruct the user to install a PDF reader here, or something
            }

尝试先加载该pdf文件? 我怀疑你的PDF阅读器会自行加载。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM