Android Question Share multiple text files - Solved

DaveW

Active Member
Licensed User
Longtime User
I would like to share multiple text files (transfer them from the android device to a PC via bluetooth). I found a function from Erel to do this for images. I tweaked it in the obvious spots but I can't make it work for text files. I am hoping there is a simple explanation that someone can supply!
B4X:
Sub ShareMultipleFiles(files As List)
   Dim i As Intent
   i.Initialize("android.intent.action.SEND_MULTIPLE", "")
   i.SetType("text/plain")
   Dim Uris As List
   Uris.Initialize
   For Each f As String In files
     Dim u As Uri
     u.Parse("file://" & f)
     Uris.Add(u)
'    Log(u)
   Next
   Dim jo As JavaObject = i
   jo.RunMethod("putParcelableArrayListExtra", Array As Object("android.intent.extra.STREAM", Uris))
   StartActivity(i)
End Sub

I know the file names are correct - I have a working share for single files using share.sharebinary.

Via Bluetooth I get this:

Sending 3 files to "MyPC"
Bluetooth Share: File Unknown file not sent​

If I try to send it via GMail I get:

Couldn't attach file​

David.
 

DaveW

Active Member
Licensed User
Longtime User
Hi Erel,

The files I want to transfer to the PC are saved in Android.data.[myprogram].files.[myfolder]

This works fine when I transfer just a single file using share.sharebinary but that is not really an option when the program may be creating 10's of files in that folder.
 
Upvote 0

DaveW

Active Member
Licensed User
Longtime User
I think we are getting off-track here.... The point is I have a number of text (XML) files in a folder. I can transfer them one at a time via bluetooth to a PC using share.sharebinary. However when I try to transfer the same files all together using the modified version of your Share multiple BMP function, I get an error.

So what is it in the function that I am getting wrong? If it will only work if the files are in a specific folder then I can copy them there, share them and then delete the copies.

David.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
There is an important point here. If you are passing file urls then they must point to files in the secondary storage or it will not work.

The fact that you are able to send a single file with sharebinary (which I'm not familiar with its implementation) doesn't mean that Gmail or any other can access the file. It is possible that sharebinary sends the file content in the intent.
 
Upvote 0

DaveW

Active Member
Licensed User
Longtime User
So I should try moving the files I want to share to another location?

By secondary storage do you mean they have to be on an SD card?
 
Upvote 0

DaveW

Active Member
Licensed User
Longtime User
Ok, Got it sorted at last! The "trick" seems to be that the Uri Parse has to refer to the path relative to DirDefaultExternal. Using the actual path (even though this is the same) does not work. So I can now use this function to send multiple text files from a folder that is a subfolder of the DirDefaultExternal folder:
B4X:
Sub ShareMultipleFiles(path As String, files As List)  'Path = name of the subfolder, files = list of file names
   Dim i As Intent
   i.Initialize("android.intent.action.SEND_MULTIPLE", "")
   i.SetType("text/plain")
   Dim Uris As List
   Uris.Initialize
   For Each f As String In files
     Dim u As Uri
     u.Parse("file://" & File.DirDefaultExternal & "/" & path & "/" & f)
     Uris.Add(u)
   Next
   Dim jo As JavaObject = i
   jo.RunMethod("putParcelableArrayListExtra", Array As Object("android.intent.extra.STREAM", Uris))
   StartActivity(i)
End Sub
 
Upvote 0
Top