Android ACTION_SEND,带有特殊文件名

时间:2018-03-22 10:15:07

标签: android android-intent share send

我曾经使用以下代码从我的应用程序共享文件:

Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(fPath)));
shareIntent.setType(fType);
mActivity.startActivity(Intent.createChooser(shareIntent, "SHARE"));

它通常可以正常工作,但最近我发现它会生成"没有应用可以执行此操作"如果文件名中有特殊字符,例如" ="或中文/日文字符。

我尝试使用推荐的" FileProvider"提供我的文件并将内容uri传递给发件人。但是,并非所有目标应用程序都可以很好地支持内容,例如, Wechat / EsfileManager等。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

尝试仅使用 URLEncoder fileName

              /* your file path */
fpath =  Environment.getExternalStorageDirectory() + File.separator + URLEncoder.encode(fileName);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(fPath)));