How to Open a PDF in an Android-Unity3D App?

前端 未结 2 1137
刺人心
刺人心 2021-01-28 18:40

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 lesso

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-28 18:59

    Ok, finally I got the solution! As you can read here Android permissions changed in Nougat (v.7) so that's why I wasnt able to open the pdf, the sistem was blocking it.

    The solution was simple, I just lowered the target API level to 23 (Android 6.0 'Marshmallow').

    Here's my code if someone is interested:

    void openPDF(){ string namePDF = "test"; TextAsset pdfTem = Resources.Load("PDFs/"+namePDF, typeof(TextAsset)) as TextAsset; System.IO.File.WriteAllBytes(Application.persistentDataPath + "/"+namePDF+".pdf", pdfTem.bytes); Application.OpenURL(Application.persistentDataPath+"/"+namePDF+".pdf"); }

提交回复
热议问题