version 1.0 Introduction
Have you ever wondered how you can save a file in the Documents or the Downloads folder?
After a brainstorming session I had with [B]NJDude[/B] (was actually his idea), the PublicFile class was born and will assist you with this task from now on.
Latest package (library files and samples)
Precompiled sample APK
How to use
IMPORTANT: IT DOES NOT WORK IN THE EMULATOR. USE A REAL DEVICE!
Add this to your manifest file:
Now, the only thing you need is the PublicFile.Save method.
Choose the desired location+name, pass an InputStream to it and you are done!
Dim MyFile as PublicFile = MyFile.Save(MyFile.DirDownloads, "file.zip", Input)
Where Input is an InputStream containing the data to be saved.
Saving a text file:
'The text to be written Dim Text As String = "b4a-rocks!" 'Yeap, it does :D 'Create an InputStream and add the text to it Dim Input As InputStream Dim Data() As Byte = Text.GetBytes("UTF8") Input.InitializeFromBytesArray(Data, 0, Data.Length) 'Create a PublicFile and pass the InputStream Dim MyFile As PublicFile MyFile.Save(MyFile.DirDocuments, "publicfile.txt", Input)
Saving an image file:
'Open the picture stream Dim Input As InputStream Input = File.OpenInput(File.DirAssets, "image.jpg") 'Create a PublicFile and pass the picture stream Dim MyFile As PublicFile MyFile.Save(MyFile.DirPictures, "publicfile.jpg", Input)
Available PublicFile.Dir(...) constants:
Don't panic tips:
- In some devices, some folder locations may not be available.
- The Gallery, is a virtual folder that is updated whenever the system has indexed your file. That means that your saved picture will appear few moments later.
- Initial version
That's all for now folks!