簡體   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