android studio共享CSV文件请求不包含数据

时间:2019-05-27 03:06:13

标签: android

我想将我的csv文件共享给任何操作,例如蓝牙,发送到电子邮件等

 final String filename = Environment.getExternalStorageDirectory() + "/Folder" + "/" + "mycsv.csv";



  Intent sharingIntent = new Intent();
                        sharingIntent.setAction(Intent.ACTION_SEND);
                        sharingIntent.putExtra(Intent.EXTRA_STREAM, filename);
                        sharingIntent.setType("text/comma_separated_values/csv");
                        startActivity(Intent.createChooser(sharingIntent, "share file with"));

输出将是不包含任何数据的请求

1 个答案:

答案 0 :(得分:0)

我认为filename需要一个file://前缀。 Android要共享任何类型的文件,需要通用标识符或Uri

final String fileUriString = "file://" + Environment.getExternalStorageDirectory() + "/Folder" + "/" + "mycsv.csv";

此外,将type更改为text/csv

Intent sharingIntent = new Intent();
sharingIntent.setAction(Intent.ACTION_SEND);
sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse( fileUriString ) ) ;
sharingIntent.setType("text/csv");
startActivity(Intent.createChooser(sharingIntent, "share file with"));

有关更多信息,请参见this answer