Dim CC As ContentChooser, TempUri As String, b() As Byte
CC.Initialize("CC")
CC.Show("*/*", "Choose the binary file")
Wait For CC_Result (Success As Boolean, Dir2 As String, FileName2 As String)
If Success Then
TempUri = FileName2 ' This is actually a content URI
b = File.ReadBytes(Dir2, FileName2)
' Make some modifications to b()
' Save back to the original location
WriteBytesToContentUri(Dir2, FileName2, b)
Else
ToastMessageShow("No files selected. File not imported", True)
Return
End If
Sub WriteBytesToContentUri(Dir As String, FileName As String, Data() As Byte)
Dim r As Reflector
Dim context As JavaObject
context = r.GetContext
Dim uri As JavaObject
uri.InitializeNewInstance("android.net.Uri", Array("parse", "content://com.android.providers.downloads.documents/document/" & FileName.SubStringAfterLast("/")))
Try
Dim out As OutputStream
out = context.RunMethod("getContentResolver", Null).RunMethod("openOutputStream", Array(uri))
Dim outStream As OutputStreamWrapper
outStream.Initialize(out)
outStream.WriteBytes(Data, 0, Data.Length)
outStream.Close
Catch
Log(LastException)
ToastMessageShow("Error saving file: " & LastException.Message, True)
End Try
End Sub