Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/191.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何通过intent共享文件夹?_Android - Fatal编程技术网

Android 如何通过intent共享文件夹?

Android 如何通过intent共享文件夹?,android,Android,我找到了通过蓝牙/云存储/wifi共享图像文件的代码。但是我如何共享整个文件夹呢?这是我的密码- 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")

我找到了通过蓝牙/云存储/wifi共享图像文件的代码。但是我如何共享整个文件夹呢?这是我的密码-

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");
    share.setType("image/*");

    // 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!"));
}

使用
Intent.ACTION\u SEND\u MULTIPLE
代替
Intent.ACTION\u SEND

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

ArrayList<Uri> files = new ArrayList<Uri>();                    
for(String path : filesToSend /* List of the files you want to send */) {
    File file = new File(path);
    Uri uri = Uri.fromFile(file);
    files.add(uri);
}

intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files);
startActivity(intent);
Intent Intent=新Intent();
intent.setAction(intent.ACTION\u SEND\u MULTIPLE);
intent.putExtra(intent.EXTRA_主题,“这里有一些文件”);
intent.setType(“*/*”);/*允许任何文件类型*/
ArrayList files=新的ArrayList();
for(字符串路径:filesToSend/*要发送的文件列表*/){
文件=新文件(路径);
Uri=Uri.fromFile(文件);
添加(uri);
}
intent.putParcelableArrayListExtra(intent.EXTRA\u流,文件);
星触觉(意向);
Intent Intent=new Intent();
intent.setAction(intent.ACTION\u SEND\u MULTIPLE);
intent.putExtra(intent.EXTRA_主题,“这里有一些文件”);
intent.setType(“*/*”);/*允许任何文件类型*/
//获取此特定位置中的所有文件
File[]filesToSend=新文件(“/sdcard/myDocs”).listFiles();
ArrayList files=新的ArrayList();
对于(文件:filesToSend){
Uri=Uri.fromFile(文件);
添加(uri);
}
intent.putParcelableArrayListExtra(intent.EXTRA\u流,文件);
星触觉(意向);

更新的答案。我的答案是正确的,请将其标记为正确。我想共享此文件夹
sdcard/myDocs
您可以尝试类似于
File[]filesToSend=new File(“/sdcard/myDocs”).listFiles()的操作?我应该用什么替换它?我试着把它放在“File File=newfile(path);”之后,但是我得到了很多错误
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND_MULTIPLE);
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);
    files.add(uri);
}

intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files);
startActivity(intent);