1

There are a lot of tutorials on how to save strings to text files, and how to share text files via an intent (here's an example of the latter).

But what if I want to skip the middleman and not have my string saved to the filesystem? Is there any way to provide a string as a text file through an intent without actually saving it to the filesystem? Like through a stream or something? To clarify, I don't want it provided as just text; I want the receiving app to think it's actually a file.

Trevortni
  • 566
  • 4
  • 20

1 Answers1

0

There is nothing really easy for that. EXTRA_STREAM takes a content Uri. You would have to create your own ContentProvider that handled openFile() and transferred your string over via a ParcelFileDescriptor-based pipe.

This provider demonstrates the technique. In my case, I am reading in an asset and streaming it out; in your case, you would just stream your string (presumably as UTF-8 encoded bytes).

CommonsWare
  • 954,112
  • 185
  • 2,315
  • 2,367