1

I invoke the browser as follows:

    Uri uri = DocProvider.GetDocumentUri("Help.html");
    Intent browser = new Intent(Intent.ACTION_VIEW);
    browser.setDataAndType(uri, "text/html");
    browser.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_PREFIX_URI_PERMISSION);
    startActivity(Intent.createChooser(browser, "Help File"));

The DocProvider created the following uri:

content://com.rtsservices.rts_services.docprovider/document/Help.html

The Help.html referenances images in the same directory: (i.e. AircraftSize.png, ...) Chrome opens the html file, but I get an error when trying to access resources in the same directory, before making any calls to my DocProvider.

2022-01-11 11:52:19.921 7247-18601/com.rts_services.controller E/DatabaseUtils: Writing exception to parcel
    java.lang.SecurityException: Permission Denial: reading com.rts_services.controller.service.DocProvider uri content://com.rtsservices.rts_services.docprovider/document/AircraftSize.png from pid=7446, uid=10252 requires that you obtain access using ACTION_OPEN_DOCUMENT or related APIs
        at android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:841)
        at android.content.ContentProvider.semEnforceReadPermission(ContentProvider.java:758)
        at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:684)
        at android.content.ContentProvider$Transport.query(ContentProvider.java:239)
        at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:106)
        at android.os.Binder.execTransactInternal(Binder.java:1190)
        at android.os.Binder.execTransact(Binder.java:1159)

I though Intent.FLAG_GRANT_PREFIX_URI_PERMISSION should provide access to these uri's. What am I missing ?

r.t.s.
  • 585
  • 1
  • 4
  • 12
  • My guess is that your URLs to your images do not start with `content://com.rtsservices.rts_services.docprovider/document/Help.html`. From the docs, "Another URI is considered a prefix match only when scheme, authority, and all path segments defined by the prefix are an exact match". Also, I would not assume that the user has a browser that supports the `content` scheme. – CommonsWare Jan 11 '22 at 18:23

1 Answers1

0

java.lang.SecurityException: Permission Denial: reading com.rts_services.controller.service.DocProvider uri content://com.rtsservices.rts_services.docprovider/document/AircraftSize.png from pid=7446, uid=10252 requires that you obtain access using ACTION_OPEN_DOCUMENT or related APIs

Chrome is clever and constructed the right content scheme for the picture file.

Only your document provider will not provide it as it gave no read permission for it.

We do not know how you implemented your extended ContentProvider. I made one too and it delivers the pictures to Chrome: Serving a html file with FileProvider or own ContentProvider

blackapps
  • 8,011
  • 2
  • 11
  • 25
  • I had my own content provider, as I exported it. I implemented using androidx.core.content.FileProvider thinking maybe I did something wrong. It behaves the same way ... the uri's are slightly different ... but the same problem. The various browsers (Chrome, Samsung Internet, HTML Viewer) can all access the html file, but when they tried to load the references img files ... they do not have permission – r.t.s. Jan 15 '22 at 20:18
  • Yes i know. I knew. But yours did not work for you. So i suggested mines which would work for you too. Did you try it? I dont understand your reaction. It's little work to try it.. You will see the pictures loaded. Thats what you want isn't it ? – blackapps Jan 15 '22 at 20:19
  • OK I created a provider that overides the getType method. It gets called when I access the html file refererenced in the Uri in the intent and does return "html". But I still get the same errors when it tries to open the img files that are referenced from the html file and that are in the same area as the html. The URIs for these refererences all look right. The getType method is not reached for these referenced resources. So it is generating the error without calling the content provider for these resources. I am on Android 11. – r.t.s. Jan 15 '22 at 21:23
  • `created a provider that overides the getType method. ` ? You should have tried my provider. Why didn't you? – blackapps Jan 16 '22 at 06:59