Screenshot stored to gallery

jima

Member
Licensed User
Longtime User
Hi All,

I am modifying the screen shot program from the docs so that the output goes directly to the gallery so users can email it, etc. I tried hard-coding "image" as the directory but that was a no go.

So what directory name do I use? There is something called DIRECTORY_PICTURES defined in android but I don't know how I would refer to that from within B4A.

Also, is there a comprehensive list of directory path specifications we can use when outputing (or inputting) particular types of files like pictures, music, etc for B4A programmers?

Thanks for all help!:sign0104:
 

nfordbscndrd

Well-Known Member
Licensed User
Longtime User
If the "screen shot program" you are referring to is the one in the Documentation Wiki, it saves pictures to the root directory using the following code:

Out = File.OpenOutput(File.DirRootExternal, dt & ".png", False)

On both of my tablets, DirRootExternal has a folder named "Pictures". I haven't tried it, but I would bet that you can just add "Pictures" to the line of code above.
 
Upvote 0

jima

Member
Licensed User
Longtime User
After more digging...

Thanks to nfordbscndrd and all others who pondered this problem.

To paraphrase John Lennon, "if there's such a thing as a genius, Erel is one"

To get your screen shot immediately available to the gallery (and other apps), add this code towards the bottom of the doc example:

Dim fullfilepath,ffilename As String
ffilename = dt & ".png"
fullfilepath = File.DirRootExternal
Out = File.OpenOutput(fullfilepath, ffilename, False)
Bmp.WriteToStream(Out, 100, "PNG")
Out.Close
Dim intent1 As Intent
intent1.Initialize ("android.intent.action.MEDIA_SCANNER_SCAN_FILE","file://"_
& fullfilepath&"/"&ffilename)
Dim phone1 As Phone
phone1.SendBroadcastIntent(intent1)

I discovered this solution after researching on the regular android developer forum and discovered the general topics of "broadcast" and "mediascanner".

Then, I searched the B4A forum and wiki and found code similar to the above that Erel had provided as a example in a different context.

Again, thanks to all.
 
Upvote 0
Top