Android Code Snippet ðŸ“Œ [B4A] Save a file to the Download folder (and document, pictures, music, movies, dcim folders)

Hello everyone, 👋

With the latest Android restrictions, direct access to the Download folder is no longer possible. However, by using MediaStore, we can save files in a way that’s fully compatible with the new system policies.

🔹 What does this snippet do?
✅ Saves a file directly to the Download folder
✅ Fully compatible with the latest Android versions
✅ Does not require special permissions like WRITE_EXTERNAL_STORAGE
✅
The app can be published on Google Play without special permissions

I’ve created a simple solution in B4A that leverages MediaStore to bypass these restrictions and make saving files to the Download folder easy and safe.

📂 Usage example:
This code demonstrates how to save a file to the Download folder using MediaStore and doesn’t require extra permissions. It works seamlessly with the latest Android security policies.

🔗 You can see the full source code on Linkedin

Hope this helps! 🚀 Feel free to ask if you have any questions or suggestions.
 
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
On LinkedIn there is my next comment that brings to a better version of the code.
Please don't post direct links by Github, if I wanted I would have done it myself. Go to the LinkedIn page
 

Star-Dust

Expert
Licensed User
Longtime User
I used SaveFileToDownloads to upload a text file, e.g. logs.txt. When I use it again, the file is saved in my Download folder under the name logs (1).txt, etc. How do I know if a file already exists and how do I delete it? Can I use File.Exist and File.Delete?
It is not possible to read in the folder, so you cannot know if it already exists in it can be canceled
 

rogeriosca

Member
Licensed User
Longtime User
Hello everyone, 👋

With the latest Android restrictions, direct access to the Download folder is no longer possible. However, by using MediaStore, we can save files in a way that’s fully compatible with the new system policies.

🔹 What does this snippet do?
✅ Saves a file directly to the Download folder
✅ Fully compatible with the latest Android versions
✅ Does not require special permissions like WRITE_EXTERNAL_STORAGE
✅
The app can be published on Google Play without special permissions

I’ve created a simple solution in B4A that leverages MediaStore to bypass these restrictions and make saving files to the Download folder easy and safe.

📂 Usage example:
This code demonstrates how to save a file to the Download folder using MediaStore and doesn’t require extra permissions. It works seamlessly with the latest Android security policies.

🔗 You can see the full source code on Linkedin

Hope this helps! 🚀 Feel free to ask if you have any questions or suggestions.
Grazie! Funziona perfettamente qui!
 
Top