【问题标题】:Open pdf file on android studio and open a black screen pdf在android studio上打开pdf文件并打开黑屏pdf
【发布时间】:2019-10-10 11:03:58
【问题描述】:

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
            }

【问题讨论】:

    标签: java android pdf provider


    【解决方案1】:

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

    【讨论】:

    • 加载pdf是什么意思?感谢您的评论。
    • >String url = "example.com";意图 i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); startActivity(i);
    • 参考here
    • 我认为这行不通。我的 pdf 已经在模拟器存储中
    猜你喜欢
    • 1970-01-01
    • 2013-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-10
    • 1970-01-01
    相关资源
    最近更新 更多