Hi.
I want an image to appear in the gallery. He has used Erel's code, but it doesn't work for me.
The image is copied correctly to the Pictures folder, but does not appear in the gallery.
I thought the problem could be because the images on my device are saved in DCIM/Camera. Update the code, the image was copied correctly, but it still does not appear in the gallery.
The code I use is this
The code for DCIM was
It also copies the file, but it does not appear in the gallery
Attach the project
Thanks
I want an image to appear in the gallery. He has used Erel's code, but it doesn't work for me.
The image is copied correctly to the Pictures folder, but does not appear in the gallery.
I thought the problem could be because the images on my device are saved in DCIM/Camera. Update the code, the image was copied correctly, but it still does not appear in the gallery.
The code I use is this
B4X:
Sub Activity_Create(FirstTime As Boolean)
Dim rp As RuntimePermissions
rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
If Result Then
File.Copy(File.DirAssets, "gatito.jpg", File.DirRootExternal, "Pictures/gatito.jpg")
Dim FilePath As String = File.Combine(File.DirRootExternal, "Pictures/gatito.jpg")
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
End If
End Sub
The code for DCIM was
B4X:
Sub Activity_Create(FirstTime As Boolean)
Dim rp As RuntimePermissions
rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
If Result Then
File.Copy(File.DirAssets, "gatito.jpg", File.DirRootExternal, "DCIM/Camera/gatito.jpg")
Dim FilePath As String = File.Combine(File.DirRootExternal, "DCIM/Camera/gatito.jpg")
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
End If
End Sub
It also copies the file, but it does not appear in the gallery
Attach the project
Thanks