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.

    Code:
    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.
    Any ideas why the image is not being registered in the gallery folder?

    Thanks in advance for any help or ideas.

    Walter
     
  2. Erel

    Erel Administrator Staff Member Licensed User

Loading...
  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