Android Question Download a file from my app to user phone? (SOLVED)

Stichler

Active Member
Licensed User
I may be very bad at this so I appreciate your patience, but for the life of me I can not figure out how to have a file in my app, in this case a .pdf, and let the user download the file to their phone via a button click. Help please?
 

Mahares

Expert
Licensed User
Longtime User
I use this code, but nothing is being copied to download folder. I have permissions set properly
If you properly checked and requested runtime permissions for external in your code and your target SDK is 23 and higher in manifest, this is the code you need to copy the file from assets to a folder named Download in the default external:
B4X:
File.Copy(File.DirAssets,"christmastree.pdf",rp.GetSafeDirDefaultExternal("Download"),"christmastree.pdf")
You should find the file under: /Android/Data/your package name/files/Download
 
Upvote 0

npsonic

Active Member
Licensed User
Problem with this path is that no regular user will ever find the file from there. Best place to save this file would be Download folder in DirRootExternal.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…