After searching in the forum, I tried this code:
It works fine in Androd 4.4- but not in Android 7.0
Can anyone give me an advice, please?
B4X:
' The image
Dim bitmap As Bitmap = LoadBitmap(File.DirAssets, "prueba.jpg")
' Copy to ...files/pruebas/prueba.jpg
Dim Out As OutputStream
Dim r As RuntimePermissions
Out = File.OpenOutput(r.GetSafeDirDefaultExternal("pruebas"), "prueba.jpg", False)
bitmap.WriteToStream(Out, 100, "JPEG")
Out.Close
' "Broadcast" image to gallery
Dim Phone As Phone
If Phone.SdkVersion < 19 Then
' This works :)
Dim i As Intent
'i.Initialize("android.intent.action.MEDIA_MOUNTED", "file://" & File.Combine(r.GetSafeDirDefaultExternal("pruebas"), "prueba.jpg"))
i.Initialize("android.intent.action.MEDIA_SCANNER_SCAN_FILE", "file://" & File.Combine(r.GetSafeDirDefaultExternal("pruebas"), "prueba.jpg"))
Phone.SendBroadcastIntent(i)
Else
' This does not work :(
Dim context As JavaObject
context = context.InitializeStatic("anywheresoftware.b4a.BA").GetField("applicationContext")
Dim paths() As String = Array As String(File.Combine(r.GetSafeDirDefaultExternal("pruebas"), "prueba.jpg")) 'files to scan
Dim mediaScanner As JavaObject
mediaScanner.InitializeStatic("android.media.MediaScannerConnection")
mediaScanner.RunMethod("scanFile", Array As Object(context, paths, Null, Null))
End If
It works fine in Androd 4.4- but not in Android 7.0
Can anyone give me an advice, please?