I'm developing an Android app in Unity3D to be used in classrooms, it has buttons to display some webs and videos related to the current lesson, but now I would like to have a button that open the default-pdf-viewer in the Android Tablet and loads a PDF file that I have in a folder in my project assets.
The thing is I have been trying a lot of code from different people from StackOverflow posts and Unity community Threads, but nothing works for me.
I have already tried:
My minimum android API level is set 22 (in relation to this reddit post)
Here's my code so far:
IEnumerator openPDF() {
var path = "jar:file://" + Application.dataPath + "!/assets/test.pdf";
var savePath = Application.persistentDataPath;
WWW www = new WWW(path);
yield return www;
var error = www.error;
byte[] bytes = www.bytes;
var result = "File size : "+bytes.Length;
try{
System.IO.File.WriteAllBytes(savePath+"/test.pdf", bytes);
error = "No Errors so far";
}catch(Exception ex){
error = ex.Message;
}
Application.OpenURL(savePath+"/test.pdf");
}
When I print the www.error
string I get a "404 not Found"
.
Here's what I get when I print the path variable: jar:file:///data/[MY APP PACKAGE NAME]/base.apk!/assets/test.pdf