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.

MainView.ux

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

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

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.

@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.