Android Question Saving a picture

Stefano Di Chiano

Active Member
Licensed User
Hi,
I'm using the following code to save a picture that I previously loaded from gallery:
B4X:
        Dim out As OutputStream
        If File.Exists(File.DirRootExternal, "Uppeee/profile.jpg") Then
            out = File.OpenOutput(File.DirRootExternal, "Uppeee/profile.jpg", False)
            bmp.WriteToStream(out, 100, "JPEG")
        Else
            File.MakeDir(File.DirRootExternal, "Uppeee")
            out = File.OpenOutput(File.DirRootExternal, "Uppeee/profile.jpg", False)
            bmp.WriteToStream(out, 100, "JPEG")
        End If
        out.Close
but when I run it, I get the following error:

Even if I have the picture in the gallery I need to save it as a profile picture. So the next time the user log in, I can already show the picture without having the user to select it again.
Line 196 is: "out = File.OpenOutput(File.DirInternal, "Uppeee/profile.jpg", False)". I don't get why I get the "No such file or directory" error even if I'm using the MakeDir function just the line before.

Can anyone help me solve this issue?
 

ronell

Well-Known Member
Licensed User
Longtime User
use GetSafeDirDefaultExternal

B4X:
Sub Process_Globals
    Private rp As RuntimePermissions
End Sub

    Dim out As OutputStream
        If File.Exists(rp.GetSafeDirDefaultExternal("Uppeee"), "profile.jpg") Then
            out = File.OpenOutput(rp.GetSafeDirDefaultExternal("Uppeee"), "profile.jpg", False)
            bmp.WriteToStream(out, 100, "JPEG")
        Else
          
            out = File.OpenOutput(rp.GetSafeDirDefaultExternal("Uppeee"), "profile.jpg", False)
            bmp.WriteToStream(out, 100, "JPEG")
        End If
    out.Close
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
Should I use GetSafeDirDefaultExternal or DirInternal?
DirInternal refers to storage that is inside the app's private area. Judging by this statement ...
So the next time the user log in, I can already show the picture without having the user to select it again.
... that is exactly what you need. Using external storage of any type is more complicated and I cannot see how it would give you any benefits. Use DirInternal.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…