简体   繁体   中英

Read pdf in Android Studio

I would read a file pdf in my project. 1 step: Where do I input PDF File? in which folder? 2 step: How do I read it? I just need to open it.

I found this code but give me an error: The directory of the file si wrong

protected void openPdf()
    {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        String path =      Environment.getExternalStorageDirectory().getAbsolutePath()+" /PDF";
        File file = new File(path, "law.pdf");
        intent.setDataAndType(Uri.fromFile(file), "application/pdf");
        startActivity(intent);
    }

Replace the line

String path = Environment.getExternalStorageDirectory().getAbsolutePath()+" /PDF";

to String path = Environment.getExternalStorageDirectory().getAbsolutePath()+"/";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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