Android Tutorial Sharing files from your app with File Provider

KMatle

Expert
Licensed User
Longtime User

JohnC

Expert
Licensed User
Longtime User
I tried using this FileProvider method to share file to the devices SMS app and I noticed the URI started with "Content://" instead of "File://".

This worked on the android 7.1 and 8.x, but I got an error in the receiving SMS app on my 4.4 that said something like "File not Supported".

So basically, starting in Aug, I need to set the target API to 26, and then my app needs to manually check to see if the device's OS is < 7 and if so, use the "File://" share method, but if the OS is 7+, then use this file provider share method?

Do I have this correct?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. You should have started a new thread for these questions.
2. Tutorial about targetSdkVersion: https://www.b4x.com/android/forum/threads/87610/#content
3. The schemes are content:// and file://. The case is important.
4.
No. FileProvider works with all versions of Android.
 

Alessandro71

Well-Known Member
Licensed User
Longtime User
All the sharing examples I’ve found deal with the shared directory, forcing copying the files first into it.
What if my app has already permissions to access files outside of the private app directory?
I have a lot of big files on the external root, on which I have permissions, to share. I’d like to avoid making copies of them in my shared and then deleting them.
Is there a way to put in the manifest an additional provider path, referring to an external dir?
 

Alessandro71

Well-Known Member
Licensed User
Longtime User
Looking at the FileProvider class, it look like the shared file is copied to the "shared" directory and never deleted.
It is necessary to wipe the shared directory from time to time, to avoid cluttering with old shared files?
 

JohnC

Expert
Licensed User
Longtime User
I would say yes, otherwise it will just get bigger with more and more files over time.

However, since you don't know exactly when the other app "gets" the file after your app shares it, you can't delete the file right away, otherwise it might be deleted before the other app gets it.

What I do in situations like this, is when my app starts up, I delete any "previous" files that are in the shared directory (that were placed there during the last app's "share" function). This way, the app cleans up after itself on every new run of the app.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…