I am trying to send data to a ACTION_VIEW or ACTION_SEND intent without writing that data to a file.
Most intents want a Uri, which is usually based on a file path or url like so:
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.fromFile(new File(context.getFilesDir(), TEMP_FILE_NAME));
intent.setDataAndType(uri, "application/pdf");
context.startActivity(intent);
I would prefer that the data I am sharing with an intent not be viewable by everyone on external storage. Internal storage (as in the example above) is not granted to called intents (meaning that a pdf viewer cannot see files in my app’s private space).
Diane Hackborne alludes to data being able to be copied in the intent here: http://groups.google.com/group/android-developers/browse_thread/thread/be9b069ca8906417#
But I have not found any other data on how this would happen.
Any ideas? Thanks!
It depends what form/size your data takes, but probably the simplest option is to include the data as an “extra” on the
Intent.Extras can be of various different types, including most Java primitives (
String,int,doubleetc) andBundles andArrayLists.If you have your own class structure, you can also implement
Parcelableand include instances of your own classes as extras.However, I would say that if your data is large in volume, passing it around in memory with the
Intentis probably not the best idea. If this is the case, you may just have to bite the bullet and temporarily write the data to storage for the duration of the call and clear it up when your callingActivity/Serviceregains focus.