【问题标题】:android studio share CSV file request contain no dataandroid studio 共享 CSV 文件请求不包含任何数据
【发布时间】:2019-10-12 14:59:13
【问题描述】:

我想将我的 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"));

输出将是 no request containst no data

【问题讨论】:

    标签: android


    【解决方案1】:

    我认为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 了解更多信息。

    【讨论】:

    • 它现在对我有用,我只是缺少文件://
    猜你喜欢
    • 1970-01-01
    • 2016-08-02
    • 1970-01-01
    • 2018-06-05
    • 2016-04-24
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 2022-06-16
    相关资源
    最近更新 更多