Storing and opening local assets using LaunchUri

I am trying to do two things:

  1. Store a PDF locally in an app.
  2. Open the local stored PDF.

For item 2 I believe this scan be done using <LaunchUri Uri="file://guff.pdf" /> which should then open as long as the phone has a built in PDF viewer.

How do I go about accomplishing this?

Hey, you have to use Uno to be able to do that now (you can enumerate Uno.IO.Bundle.AllFiles to find the file and get the path). I will make a ticket so we expose the path through the Bundle API in JS.

Thanks Anders. I have not touched Uno yet so will give it go.

This was not as easy as I thought since the bundle files are actually bundled into a JAR file on Android and into a dll on windows. I made a sample where temporary store the file in the application folder and then retrieve the file path.

When testing the below code I console.log the uri variable and get the following ouput: I/BundlePathTest(10506): file:///data/data/com.BundlePathTest/files/generic.pdf which looks correct. However when I try to open the file via LaunchUri I get the unhandled exception: There is an invalid character sequence in uriString.

If I remove the third slash (file:///data... to file://data) the unhandled exception is no longer thrown and the device tries to open the file but cannot locate it.


<App Theme="Basic">
        var bp = require("BundlePath");
        var file = bp.getPath("generic.pdf");
        var uri = "file://"+file;

        module.exports = {
            file: uri
        <Button Text="Open PDF">
            <LaunchUri Uri="{file}" />

The temp file was created with the MODE_PRIVATE flag by default. I need to research some more and get back to you.

Thanks Anders.


Just wanted to follow up on this to see if you have had any time to look into this?

This is not production code, but I hope it can show you how something like this could be done using foreign code.

This has been hugely helpful. Thank you.