Reading a pdf file placed in assets folder in android

大兔子大兔子 提交于 2019-12-12 23:18:45

问题


I have a pdf file placed in my assets folder and I am firing an intent to read it. Here is my code :

 Uri path = Uri.parse("file:///android:asset/about.pdf");
   Intent intent  = new Intent(Intent.ACTION_VIEW);
   intent.setDataAndType(path, "application/pdf");
   intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
   startActivity(intent);

When I do this, apop up appears with list of applications including adobe reader but when I click on it, a dialog appears saying :"Error", the file path is not valid

Please tell me how to fix this


回答1:


Is this file in your app's assets folder? If it is, then your URI is wrong, check out this question:

How to open a pdf stored either in res/raw or assets folder?

there's an answer describing how to construct a proper URIs for your assets.



来源:https://stackoverflow.com/questions/9207203/reading-a-pdf-file-placed-in-assets-folder-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!