Android Question Opening/Saving Email Attachment using B4xpages

gregchao

Active Member
Licensed User
Longtime User
I was reading this old thread which uses manifest and intent to save an email attachment to the local app folder. With the B4xpages, this method no longer seems to work. Is there some modifications that I need to make? Or, is there another method.

My intention is to export a .zip file in an email on one device and the import the enclosed file in another device running the same app.

 

gregchao

Active Member
Licensed User
Longtime User
Thanks. Got it working.

Sending File - To send a .zip file, this article was most helpful --- https://www.b4x.com/android/forum/threads/class-fileprovider-share-files.97865/#content

I ended up using the share button code option. The only change I had to make is changing the MIME type from text to zip.

B4X:
Private Sub btnShareFile_Click
     'fill MyArray with your files to zip
     Dim FileToSend As String = "example.zip"
     Arc.AsyncZipFiles(LocalDirFullPath, myArray, Provider.SharedFolder, FileToSend, "Zip")
     Wait for Zip_ZipDone(CompletedWithoutErrors As Boolean, NbOfFiles As Int)
    Dim in As Intent
    in.Initialize(in.ACTION_SEND, "")
    in.SetType("application/zip")  'changed from in.SetType("text/plain")
    in.PutExtra("android.intent.extra.STREAM", Provider.GetFileUri(FileToSend))
    in.Flags = 1 'FLAG_GRANT_READ_URI_PERMISSION
    StartActivity(in)
End Sub


Getting File - In the receive side, I found the article you recommended to be most helpful --- https://www.b4x.com/android/forum/threads/b4x-texteditor-save-and-load-external-files.132731/#content

Again, the only change I had to make was in FileHander Module to change from text to zip file format.

B4X:
Public Sub Load As ResumableSub
    Dim cc As ContentChooser
    cc.Initialize("cc")
    cc.Show("application/zip", "Choose zip file")  'changed from cc.Show("text/*", "Choose text file")
    Wait For CC_Result (Success As Boolean, Dir As String, FileName As String)
    Dim res As LoadResult = CreateLoadResult(Success, Dir, FileName)
    If res.Success Then ExtractInformationFromURI(res.FileName, res)
    Return res
End Sub
 
Upvote 0
Top