I am building an application in which when a user press "Browse" button on the application I want to show folders from phone where user will select the file/image. Once the attachment is selected, application will show the file name in the attachments. What I am looking for is how the file attachment mechanism work in android so any code example or snippet in much appreciated.
Thanks in advance.
What you actually want to do is execute Intent.ACTION_GET_CONTENT. If you specify type to be
"file/*"
then the file picker will allow you to select file of any type from the file system.Here are a couple of reads:
This is the extracted source from the blog (courtesy of Android-er):
After acquiring path to the selected file it is up to you on how are you going to handle it: store path in a database, display it on screen, etc.
If you want to open the file with a default application, follow advices in this blog. Again, I extracted the code (courtesy of Hello World Codes):
First way:
Second way:
Please remember to leave thanks to the guys who deserve it (-.