Cassie Cassie - 1 year ago 97
Android Question

How to share folders via intent?

I have found this code for sharing image files via bluetooth/cloud storage/wifi. but how do i share the whole folder instead? here is my code-

private void shareImage() {
Intent share = new Intent(Intent.ACTION_SEND);

// If you want to share a png image only, you can do:
// setType("image/png"); OR for jpeg: setType("image/jpeg");

// Make sure you put example png image named myImage.png in your
// directory
String imagePath = Environment.getExternalStorageDirectory()
+ "/myImage.png";

File imageFileToShare = new File(imagePath);

Uri uri = Uri.fromFile(imageFileToShare);
share.putExtra(Intent.EXTRA_STREAM, uri);

startActivity(Intent.createChooser(share, "Share Image!"));

Answer Source
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SUBJECT, "Here are some files.");
intent.setType("*/*"); /* allow any file type */

//Get all files in this particular location
File[] filesToSend = new File("/sdcard/myDocs").listFiles();

ArrayList<Uri> files = new ArrayList<Uri>();
for (File file : filesToSend) {
    Uri uri = Uri.fromFile(file);

intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download