Android Question CameraEx Show picture in Gallery

walterf25

Expert
Licensed User
Longtime User
Hi All, i need to show the image taken using CameraEx class in the gallery, I found the code below which i am implementing in the Camera1_PictureTaken function right after taking the picture, i remember this working just fine before, but for some reason it is no longer working, i thought maybe i could get a fresh pair for eyes and see what i may be missing.

B4X:
Sub Camera1_PictureTaken (Data() As Byte)
    Dim filename As String = DateTime.Now & ".jpg"
    File.MakeDir(File.DirRootExternal, "Videos")
    Dim dir As String = Starter.rp.GetSafeDirDefaultExternal("Videos")
    
    camEx.SavePictureToFile(Data, dir, filename)
    camEx.StartPreview 'restart preview
    
    
    Dim FilePath As String = File.Combine(Starter.rp.GetSafeDirDefaultExternal(""), "Videos/"&filename)
    LogColor("file path for videos: " & FilePath, Colors.Blue)
    
    Dim Phone As Phone
    If Phone.SdkVersion <= 18 Then           ' min - 4.3.1
        Dim i As Intent
        i.Initialize("android.intent.action.MEDIA_SCANNER_SCAN_FILE", "file://" & FilePath)
        Phone.SendBroadcastIntent(i)
    Else
        Dim ctxt As JavaObject
        ctxt.InitializeContext
        Dim MediaScannerConnection As JavaObject
        MediaScannerConnection.InitializeStatic("android.media.MediaScannerConnection")
        Dim interface As Object = MediaScannerConnection.CreateEventFromUI("android.media.MediaScannerConnection.OnScanCompletedListener", "ScanCompleted", _
           Null)
        MediaScannerConnection.RunMethod("scanFile", Array(ctxt, Array As String(FilePath), Array As String("image/jpeg"), interface))
    End If
    
    ToastMessageShow("Picture saved." & CRLF  & "File size: " & File.Size(dir, filename), True)
End Sub

Sub ScanCompleted_Event (MethodName As String, Args() As Object) As Object
    Log(Args(0))
    Log(Args(1))
    Return Null
End Sub

The image is taken just fine and I can see it inside the folder where it is saved, on the Sub ScanCompleted_Event function i see the following logs.
/storage/emulated/0/Android/data/com.hermosa.camera/files/Videos/1565611017903.jpg
content://media/external/file/290

Any ideas why the image is not being registered in the gallery folder?

Thanks in advance for any help or ideas.

Walter
 
Top