Sub snapshot_Event (MethodName As String, Args() As Object) As Object
If Args.Length > 0 Then
Dim Filename As String = "rotrackx-track.png"
Dim Folder As String = File.DirInternal
Dim bmp As Bitmap = Args(0)
Dim Out As OutputStream
'Write the image to a file
Try
If File.Exists(Folder, Filename) Then File.Delete(Folder, Filename)
Out = File.OpenOutput(Folder, Filename, False)
bmp.WriteToStream(Out, 100, "PNG")
Out.Close
ToastMessageShow($"Screenshot saved to ${Filename}"$, False)
Catch
Msgbox2($"Error: Screenshot can not be saved.${CRLF}${LastException.Message}"$, "Save Track", "OK", "", "", Null)
Return Null
End Try
'Send the bitmap to the Gallery
Try
Dim r As Reflector
r.Target = r.GetContext
r.Target = r.RunMethod("getContentResolver")
Dim mediaStore As JavaObject
mediaStore.InitializeStatic("android.provider.MediaStore.Images.Media")
Dim Url As String = mediaStore.RunMethod("insertImage", Array As Object(r.Target, bmp, "roTrackX", "Track Screenshot"))
ToastMessageShow($"Screenshot send to the Gallery."$, False)
Catch
Msgbox2($"Error: Screenshot can not be send to the gallery.${CRLF}${LastException.Message}"$, "Save Track", "OK", "", "", Null)
Return Null
End Try
End If
Return Null
End Sub