1. *** New version of B4J is available ***
    B4J v7.8
    Dismiss Notice

Android Question CameraEx Show picture in Gallery

Discussion in 'Android Questions' started by walterf25, Aug 15, 2019.

  1. walterf25

    walterf25 Well-Known Member Licensed 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.

    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)
    'restart preview
    Dim FilePath As String = File.Combine(Starter.rp.GetSafeDirDefaultExternal(""), "Videos/"&filename)
    "file path for videos: " & FilePath, Colors.Blue)
    Dim Phone As Phone
    If Phone.SdkVersion <= 18 Then           ' min - 4.3.1
            Dim i As Intent
    "android.intent.action.MEDIA_SCANNER_SCAN_FILE""file://" & FilePath)
    Dim ctxt As JavaObject
    Dim MediaScannerConnection As JavaObject
    Dim interface As Object = MediaScannerConnection.CreateEventFromUI("android.media.MediaScannerConnection.OnScanCompletedListener""ScanCompleted", _
    "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
    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.
    Any ideas why the image is not being registered in the gallery folder?

    Thanks in advance for any help or ideas.

  2. Erel

    Erel Administrator Staff Member Licensed User

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice