Content exchange: Choose all file types from File Manager?
-
I'm currently working on an HTML app which can open and display PDF files. I'm using the HTML5 FIle Reader API to open files; it works on Desktop, but not on Ubuntu Touch.
When I try to open a file, it opens the "Choose from" panel, which tells me that "there aren't currently any apps installed that can provide this type of content". I found this a bit strange, since I thought I could choose from my filesystem directly.
If it can be of any help, my HTML is:
<input id="loadfile" type="file" />
Is there a way I could load a file from my HTML app if there are no other applications to "provide" them? If not, would it be possible to make the File Manager app provide all types of files by default, so we can select files from the filesystem?
This may be an alternate question (I'll open a different thread if requested), but in case the resolution of both problems are linked: Is there a way to make my HTML app accept PDF files from Content Exchange, so that other apps that want to send PDF files to other apps can show my app listed?
-
I don't know how complete the ContentHub api for html5 apps is. You have information here: https://api-docs.ubports.com/sdk/apps/html5/ContentHub/index.html
The message you get is because you have to specify the kind of files the app is expecting.
I normally use a qtengineviewer so I can have more control: check https://gitlab.com/cibersheep/doc-renderer
It is in alpha state though. -
@slimps said in Content exchange: Choose all file types from File Manager?:
[...] Is there a way to make my HTML app accept PDF files from Content Exchange, so that other apps that want to send PDF files to other apps can show my app listed?
Yes and no. You can be the ContentHub destination app of Documents file type, but not of pdf specifically.
Some info: https://docs.ubports.com/en/latest/appdev/guides/contenthub.htmlAn example: https://gitlab.com/TronFortyTwo/sturmreader/-/blob/master/contenthub.json
(this file is used in the manifest of the app)
-
@cibersheep Thanks for the links! I'll give them a look whenever I can.
-
I wanted to give it a try... but I can't even get to access the API! I'm trying to use the objects from the docs, but they don't seem to exist.
Are you familiar with accessing the HTML5 API? Do you know if there's something I must to to have access to that API?
-
@slimps I've never tried it. I prefer to use an qml webview as I mentioned before
Let's see if someone else with more experience with html5 only apps can answer
-
I had a similar problem and I found a solution At first, you have to add
"content_exchange"
to the list of the"policy_groups"
in your apparmor file. Then, you'll get a list of apps when clicking on the file input. Then, you can use thechange
-event of the file input to read the contents of the chosen file. E.g.:var input = document.getElementById("file"); if (input.files.length > 0) { var reader = new FileReader(); reader.addEventListener("load", function() { console.log(reader.result); }); reader.readAsDataURL(input.files[0]); }
I hope this helps a bit.
-
@schlicki2808 Amazing, it works! I was only lacking the policy group entry. Thank you so much!
-
@slimps If you are happy plaes mark as solved to help ohers Thanks https://forums.ubports.com/topic/6311/how-to-ask-a-question-and-then-mark-it-as-solved