在Android Studio上打开pdf文件,然后打开黑屏pdf

时间:2019-05-23 20:35:17

标签: java android pdf provider

Emulator。尝试打开通过文件提供程序存储在模拟器中的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
            }

1 个答案:

答案 0 :(得分:0)

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