- Home /
How to open file with external app android
Hi all! I need to open a pdf file with my Unity App in Android with a pdf reader installed on my phone. I have put the pdf inside Assets folder of my project and in Unity project preview all works very well, but when I try the app on my android's phone i get an error and the file could not be opened. I am using this C# code:
Application.OpenURL ((Application.dataPath) + "/nameofmyfile.pdf");
Thanks in advance for the help!
I also want to know how to open files created/present in game with external program. In my case, I want to send file for printing. If user has an app to do this, he should open image with that app.
Answer by D4us · Feb 19, 2016 at 04:47 PM
hi , try to make some space in your sd card ! (atleast 1 gb ) , put your pdf file in your sd card and use this
Application.OpenURL("/mnt/sdcard/YourFile.pdf");
Answer by andyRogerKats · Jun 24, 2019 at 06:52 PM
This plugin might help: https://github.com/Andy-Roger/UnityAndroidNativeFileOpener
Answer by codemaker2015 · Dec 17, 2021 at 10:51 AM
If you are trying to open any document using Application.OpenURL
then it won't work. Unity removed that support in latest versions. You can use AndroidOpenUrl.OpenUrl(documentUrl, dataType)
for these cases.
public void Example()
{
string dataType = "application/pdf";
string documentUrl = "/storage/emulated/0/Downloads/template.pdf";
AndroidOpenUrl.OpenUrl(documentUrl, dataType); // you can specify any MIME type when opening a file by explicitly specifying the dataType parameter
}
You will get a demo and installation steps of the package from the following repository.