B4J Question Send File From B4j To B4a Problem

behnam_tr

Active Member
Licensed User
Longtime User
Hi everyone


According to the above tutorial, I want to send a file (any type of file such as mp3, png, etc.)
From b4j to b4a and save on b4a
But after sending the file and saving it in memory, the file can not be used and the Android system can not open the file. Where is the problem ??

Send Code in B4j
B4X:
'Type MyMessage (Name As String, Age As Int, dbfile() As Byte)

    Dim mm As MyMessage
    mm.Initialize
   
    mm.Age = edtAge.Text
    mm.Name = edtName.Text
    mm.dbfile = File.ReadBytes(File.DirApp,"1.mp3")
   
   
    SendData (ser.ConvertObjectToBytes(mm))


Receive code in B4a
B4X:
Dim mm As MyMessage = ser.ConvertBytesToObject(data)
   
    edtAge.Text = mm.Age
    edtName.Text = mm.Name
   
   
    rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result = False Then
        ToastMessageShow("No permission!",True)
        Return
    End If
   

    'convert the array of bytes to file
    File.WriteBytes(File.DirRootExternal, "1.mp3", data)
   
    Sleep(100)
    Log("File saved...")
   
    If File.Exists(File.DirRootExternal, "1.mp3") Then
        Log("File Found....")
    Else
        Log("File Not Found....")
    End If
 
Top