简体   繁体   English

我正在将pdf下载到内部存储中,但是我的pdf查看器找不到它们

[英]I am downloading pdf's to internal storage but my pdf viewer can not find them

I download a pdf file to internal storage and then programmatically create buttons that take them to an action view. 我将pdf文件下载到内部存储中,然后以编程方式创建将其带到操作视图的按钮。 I can listFiles[] and Toast that they are there but the pdf viewer says file does not exist or file can not be viewed. 我可以在listFiles []和Toast中找到它们,但是pdf查看器显示文件不存在或无法查看文件。

These are the main components of the write to internal storage during download. 这些是下载期间写入内部存储器的主要组成部分。

private File file;
file = new File(mContext.getFilesDir(), filename+".pdf");
// Output stream to write file in internal storage
                    OutputStream output = new BufferedOutputStream(new FileOutputStream(file));

Then in another activity I get the filenames from the database and create a table with buttons 然后在另一个活动中,我从数据库中获取文件名,并创建带有按钮的表

// ....Inside a for loop ..... 
Button c3 = new Button(this);
        c3.setText("view");
        c3.setId(p.getPosterID());
        c3.setOnClickListener(new View.OnClickListener(){
            public void onClick(View v){
                File pdfFile = getBaseContext().getFileStreamPath(filename+".pdf");
                if (pdfFile.exists()){
                    Uri path = Uri.fromFile(pdfFile);
 //================================================================================
                    Log.d("path: ", path.toString());
    //this will log: file:///data/data/com.myapp.posterviewer/files/5453b54b83b5f.pdf
 //================================================================================
                    Intent pdfIntent = new Intent(Intent.ACTION_VIEW);
                    pdfIntent.setDataAndType(path, "application/pdf");
                    pdfIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    try{
                        startActivity(pdfIntent);
                    }
                    catch(ActivityNotFoundException e){
                        Toast.makeText(ListPosters.this, "No Application Available", Toast.LENGTH_LONG).show();
                    }
                }
                else{
                    Toast.makeText(ListPosters.this, "The file does not exist", Toast.LENGTH_LONG).show();
                }
            }
        });

Am I generating the path right with Uri path? 我是否使用Uri路径生成路径? I am not able to see the files from windows explorer when in the app folder either. 在应用程序文件夹中时,我也无法从Windows资源管理器中看到文件。 But all my checks say file is exists and I thought that would be in the app root folder. 但是我所有的检查都说该文件存在,我认为那应该在应用程序的根文件夹中。

Internal Storage Only Visible to your Application. 内部存储仅对您的应用程序可见。 The OutSide Application(Pdf Viewer) Cannot Access it. OutSide应用程序(Pdf查看器)无法访问它。 Save you Pdf file in External Storage and then open it via Pdf Viewer 将Pdf文件保存在外部存储中,然后通过Pdf Viewer打开

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

相关问题 在内部存储器中下载PDF文件 - Downloading PDF files in internal storage 如何将 PDF 复制到我的内部存储中? -安卓工作室 - How do I copy a PDF into my internal storage? -Android studio 将 PDF 保存到内部存储 - Saving a Pdf to internal storage 在手机的内部存储中找不到下载的文件 - Can't find the downloaded file in my phone's Internal storage 我正在使用Pdf查看器库打开Pdf文件。 它显示了很长时间的pdf加载 - I am using Pdf viewer library to open Pdf file. It shows pdf loading for a long time 我如何在Android手机上找到我的pdf文件 - How i can find my pdf file on android phone 为什么我无法发送存储在我的应用程序内部存储中的文本文件? - Why am I unable to send text file stored in my app's internal storage? 从 firebase 成功下载 pdf 后,我在真实设备的下载文件夹中找不到 pdf - After successfully download pdf from the firebase I can not find the pdf on the download folder in my real device 我们如何从Firebase下载Android Studio中的文件(pdf),使其不出现在手机的内部存储中? - How can we download file(pdf) in android studio from firebase such that it doesn't appear in phone's internal storage? 在哪里可以找到模拟器上的内部存储 - where can I find internal storage on emulator
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM