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!

@Requiem99

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”);

This plugin might help: GitHub - Andy-Roger/UnityAndroidNativeFileOpener: Open files from a Unity app natively on an Android device.

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.