0

I'm trying to create a Delphi 11 app for Android 12, which opens a local HTML file with local images.

The local HTML file is stored here:

content://com.embarcadero.MyAppDir/fileprovider/external_public_files/MyAppDir/Pics/MyFile.html

The local images are stored in the same local directory.

I can get Chrome and other browsers to open the HTML file without any problem, except that none of the images are displayed. Instead of my images the browser simply shows small icons with a broken corner, indicating an error.

None of these work for me:

<img src="mypic.jpg"/>
<img src="/storage/emulated/0/MyAppDir/Pics/mypic.jpg"/>
<img src="com.embarcadero.MyAppDir/fileprovider/external_public_files/MyAppDir/Pics/mypic.jpg"/>

I just don't know what else to try after src=.

Daniel
  • 1
  • 1

1 Answers1

0

content://com.embarcadero.MyAppDir/fileprovider/external_public_files/MyAppDir/Pics/MyFile.html

That is a content scheme uri.

You added a grand read permission to the intent so the browser could read the html source using the uri.

>><img src="mypic.jpg"/>

That is the src attribute that you should use.

Now the browser will try to read the image after having build an uri for it. The uri the browser build will be:

   content://com.embarcadero.MyAppDir/fileprovider/external_public_files/MyAppDir/Pics/mypic.jpg

But unfortunately the browser has no read permission for this uri as you did not give it in the intent. (Not that it would be possible to do so).

Yes the old times were better. A browser just changed /path/file.html to /path/picture.jpg and all worked.

blackapps
  • 8,011
  • 2
  • 11
  • 25
  • Thank you blackapps. I'm not sure if I understand it correctly. Are you saying that what I am trying to do is just not possible? ("...Not that it would be possible to do so...". – Daniel Oct 07 '22 at 18:19
  • It is possible to share multiple `content:` URIs in a single `Intent`. Use `Intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM)` with an `ArrayList` of content URIs. – Remy Lebeau Oct 07 '22 at 19:29
  • @Remy Lebeau. Yes you can share multiple uries in that way but not the permission to read them. The permission grant is only for one file. Moreover one would have to parse the html source first to extract all image file names in order to build uries for them. Who would do that? – blackapps Oct 07 '22 at 20:09
  • @blackapps From Jelly Bean onward, if `Intent.setClipData()` is not used then `startActivity()` will copy `EXTRA_STREAM` into a `ClipData` for you... – Remy Lebeau Oct 07 '22 at 20:35
  • @blackapps ... Grant flags on an `Intent` are applied to all URIs in a `ClipData`, per the [documentation](https://developer.android.com/reference/android/content/Intent#setClipData(android.content.ClipData)): "*The main feature of using [ClipData] over the extras for data is that `FLAG_GRANT_READ_URI_PERMISSION` and `FLAG_GRANT_WRITE_URI_PERMISSION` will operate on any URI items included in the clip data. This is useful, in particular, if you want to transmit an Intent containing multiple `content:` URIs for which the recipient may not have global permission to access the content provider.*" – Remy Lebeau Oct 07 '22 at 20:38
  • So, in this context, how to code the paths of (a) the intent and (b) the src= section of the HTML?I have tried content:.. etc and tried /storage/emulated/...etc and still get broken images. – Daniel Oct 07 '22 at 21:10
  • @Remy Lebeau, did you actually try to share multiple images with FileProvider uries to for instance GMail? You would see that only the first file can be read. For action view i did not test this and why should action view accept multiple uries? – blackapps Oct 07 '22 at 21:18
  • @Remy Lebeau, FYI: https://stackoverflow.com/questions/73925907/android-kotlin-permission-denial-reading-fileprovider-sending-multiple-files-w/73926052#73926052 – blackapps Oct 07 '22 at 21:21
  • @blackapps I haven't tried anything myself, because I don't code for Android. I'm just stating facts that I've read from other answers, docs, and blogs. And yes, I'm aware of the solution mentioned in that link. I pointed out that solution in my last comment (the grant flag applies to all URIs in a `ClipData` added to the `Intent`). – Remy Lebeau Oct 07 '22 at 21:25
  • Sorry my terminology not so good. What I mean by broken images is that the browser does not display the image, it only shows a small icon with a broken corner, indicating en error. The error is as mentioned above: the browser fails to find or has no read permission to access the image file. – Daniel Oct 08 '22 at 11:21
  • Ok. Now how do you want to solve your problem? Or is it not important? – blackapps Oct 08 '22 at 11:55
  • Huh? It's important enough for me to be here, trying to get an answer, but not important enough to put up with attitude so I thank you for your input and I am out of here. – Daniel Oct 08 '22 at 12:02
  • @Daniel did you try the solution I mentioned? Create a `content:` URI for one of the images in question, and add that URI to the `Intent`, alongside the `content:` URI of the HTML page. Does the image show now? If so, then apply the solution to the rest of the images. – Remy Lebeau Oct 10 '22 at 18:10
  • @Remy, yes, I did, thank you, but for some reason it didn't work. I tried several combinations of scr=xxxx and content:yyyy but none of them worked for me. That's why I asked how to code the xxxx and yyyy part, but the thread went south after that. :) – Daniel Oct 11 '22 at 14:41
  • 1
    You should only use and now please show full code to view the html file. – blackapps Oct 11 '22 at 14:46
  • Just as an aside. In the end I kind of solved it by creating a pdf of the html on the fly at runtime and display that pdf., which is easy enough, as the pdf contains several images and little else.. Not exactly what I wanted but good enough. – Daniel Oct 11 '22 at 14:46
  • @Daniel yes, please edit your question to show the actual code you are using to create the `Intent` that opens the HTML file (including the code you tried to enable permissions for multiple `content:` URIs) – Remy Lebeau Oct 11 '22 at 20:29