Android Question camex save picture problem

hung

Active Member
Licensed User
Longtime User
I have an app using similar code as below to take photo then save to device.

No error prompted, but I could not find the photo taken.

B4X:
Sub Camera1_PictureTaken (Data() As Byte)
    Dim filename As String = "1.jpg"
    Dim dir As String = File.DirInternal
   
    camEx.SavePictureToFile(Data, dir, filename)
    camEx.StartPreview 'restart preview
    ToastMessageShow("Picture saved." & CRLF  & "File size: " & File.Size(dir, filename), True)
End Sub

Android targetSdkVersion is 30 and I am using Xiaomi 9T Pro (Android 11 RKQ1.200826.002)

The File.DirInternal is "/data/user/0/abc/files/"
where abc is my package name.
 

Brian Dean

Well-Known Member
Licensed User
Longtime User
File.DirInternal is (and always has been) storage that is private to the app, inaccessible to the User and to other apps (unless on a "rooted" device).

You need to use one of the options listed here to save the data somewhere else.
 
Upvote 0

hung

Active Member
Licensed User
Longtime User
Thank you Brian. I follow your guide to update program as below
B4X:
Private Sub cam_PictureTaken (Data() As Byte)
    Dim dir As String
    dir = gRp.GetSafeDirDefaultExternal("")
    camex.SavePictureToFile(Data, dir, "photo1.jpg")
    camex.StartPreview
    ToastMessageShow(dir & "/photo1.jpg", False)   
End Sub

I could find the photo1.jpg in android/data/... But the default photo album cannot see the photo taken by my program.

How could I put the photo taken into a place for default photo album to see?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

hung

Active Member
Licensed User
Longtime User
Upvote 0
Top