Android Question Share Image and text as one file with fileprovider share

JNG

Member
Licensed User
Hi!

I have image and some related text to this image. I wanted to share this with fileprovider how can I achieve it.

Dim Bmp As Bitmap
Bmp.InitializeMutable(320dip,300dip)
Dim Out As OutputStream
Out = File.OpenOutput(File.DirInternal, "temp.png", True)

Bmp.Initialize(File.DirAssets,"b4a.png")
Bmp.WriteToStream(Out, 100, "PNG")


Out.Close
Dim html As String = $"

<p>This is a test to send text and image both</p>
<img src='file://${File.Combine(File.DirInternal, "temp.png")}'/>
<p>more text</p>
"$
File.WriteString(File.DirInternal,"html1",html)

regards
jng
 

JNG

Member
Licensed User
I have tried this but it is sharing only the last file
B4X:
File.Copy(File.DirAssets, "declaration.pdf", Starter.shared, "declaration.pdf")
    File.Copy(File.DirAssets,"b4a.png",Starter.shared,"b4a.png")
    Dim in As Intent
    in.Initialize(in.ACTION_SEND, "")
    in.SetType("*/*") 'it is not related to the file itself.
    in.PutExtra("android.intent.extra.STREAM",  CreateFileProviderUri(Starter.shared, "declaration.pdf"))
    in.PutExtra("android.intent.extra.STREAM",CreateFileProviderUri(Starter.shared,"b4a.png"))
    in.Flags = 1
    StartActivity(in)

and

B4X:
File.Copy(File.DirAssets, "declaration.txt", Starter.shared, "declaration.txt")
    File.Copy(File.DirAssets,"b4a.png",Starter.shared,"b4a.png")
    Dim in As Intent
    in.Initialize(in.ACTION_SEND, "")
    in.SetType("*/*") 'it is not related to the file itself.
    in.PutExtra("android.intent.extra.TEXT",  CreateFileProviderUri(Starter.shared, "declaration.txt"))
    in.PutExtra("android.intent.extra.STREAM",CreateFileProviderUri(Starter.shared,"b4a.png"))
    in.Flags = 1
    StartActivity(in)


regards
jng
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
Please use [code]code here...[/code] tags when posting code.

The html file will not help.
Sharing a file: https://www.b4x.com/android/forum/threads/share-txt-files.73166/#post-464921

You can add more "extras" to the intent.
Try with "android.intent.extra.TEXT" as the key.

Thanks erel this is working very well.
I have just a small question please. In manifest u added a permission to write to the shared folder. If i want to read from it do i add also the read permission?

Thanks, ilan
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
I noticed that if i unistall my app all files created in the shared folder are deleted.

So any other solution to keep those files?
I am creating backup files for the situation the app was removed or is no more accessable and the user need to uninstall the app so using that folder makes no sense in this case. Should i use again defaultrootexternal?
Will i be able to upload those files to google drive like i can from the shared folder?

Thank you
 
Upvote 0
Top