B4A Library [class] FileProvider - share files

Status
Not open for further replies.
Edit: FileProvider is included as an internal library now.
After investigating several issues with the current FileProvider code that you can find in the forum, I decided to make some improvements and implement it in a class.

Starting from Android 7 (API 24) you cannot directly share file uris with other applications. You need to use FileProvider.

The FileProvider class should work on all Android versions (4+).

Instructions:

1. Add a reference to FileProvider library.

2. Add to the manifest editor:
B4X:
AddManifestText(<uses-permission
   android:name="android.permission.WRITE_EXTERNAL_STORAGE"
   android:maxSdkVersion="18" />
)

AddApplicationText(
  <provider
  android:name="android.support.v4.content.FileProvider"
  android:authorities="$PACKAGE$.provider"
  android:exported="false"
  android:grantUriPermissions="true">
  <meta-data
  android:name="android.support.FILE_PROVIDER_PATHS"
  android:resource="@xml/provider_paths"/>
  </provider>
)
CreateResource(xml, provider_paths,
   <files-path name="name" path="shared" />
)
files-path = File.DirInternal

SS-2018-10-03_15.03.31.png


Current version: 1.00
 

Attachments

  • FileProviderExample.zip
    24.6 KB · Views: 3,086
Last edited:

udg

Expert
Licensed User
Longtime User
Hi,
I'm using the code from this thread in a class embedded in a library.
When it comes to sub CheckInstallationRequirements we read Wait For Activity_Resume '<-- wait for Activity_Resume, as way to wait for a user decision.
Is it safe to use it in the context above? Should I read that activity as the one that initialized the class and later launched the new install request?

I tried "as is" and it works, but I prefer to ask before publishing a possibly failing lib.
 
Status
Not open for further replies.
Top