Android将文件附加到GMAIL-无法附加空文件 [英] Android Attaching a file to GMAIL - Can't attach empty file

查看:62
本文介绍了Android将文件附加到GMAIL-无法附加空文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序,该程序始终将相同的文件附加到GMAIL(撰写">附加文件">打开自">我的程序").它将始终选择相同的文件.

I had a program that would always attach the same file to GMAIL (Compose > Attach File > Open From > "MyProgram"). It would always select the same file.

它正在做什么:

String path = Environment.getExternalStorageDirectory() + "/file.3gp";
File f = new File(path);
Uri data = Uri.fromFile(f);
Intent i = new Intent();
i.setData(data);
setResult(Activity.RESULT_OK, i);
finish();

在Android 6.0之前,它一直运行良好. 现在,当我尝试使用它时收到以下错误:

This was working fine until Android 6.0. Now, I receive the following error when trying to use it:

无法附加空文件

Can't attach empty file

Astro文件共享给了我同样的错误(可能是旧版本).

Astro File Sharing is giving me the same error (can be an old build).

但是,我安装了ES File Explorer,当我执行相同的例程并选择文件时,我会收到一个对话框,显示:

However, I installed ES File Explorer, and when I do the same routine, and select the file, I receive a Dialog which says:

将文件另存为

Pick up file as

  • 正常的Android方式(用于MMS,Gmail等)
  • 文件方式(如果以上方法失败,请尝试此方法)

文件方式"将与我的程序一样失败. 正常的Android方式"可以正常工作.

The "File Way" will fail as my program does. The "Normal Android Way" will work fine.

有人对它的功能有任何想法,以便我可以复制吗?

Does anyone have any idea on what it does, so I can replicate?

提前谢谢!

OBS:已经尝试了很多次putExtra(STREAM,path),但是没有成功.

OBS: Already tried the putExtra(STREAM, path) a lot of times, but without success.

推荐答案

好吧,经过大量研究并截取了一些Intent,让它现在可以工作了.

Ok, got it to work now, after a lot of research and intercepting some Intents.

我要做的就是将file:///更改为content://.

What I had to do was change the file:/// to content://.

我是根据Android上的以下信息进行此操作的: https://developer.android.com/reference/android/support/v4/content/FileProvider.html

I did this following this information from Android: https://developer.android.com/reference/android/support/v4/content/FileProvider.html

唯一的主要变化是我使用了/sdcard/file.ext的硬编码路径. 另外,这行

The only major change was that I used a hard-coded path to /sdcard/file.ext. Also, the line

getUriForFile(getContext(), "com.mydomain.fileprovider", newFile);

已更改为

Uri contentUri = FileProvider.getUriForFile(this, "com.mydomain.fileprovider", newFile);

还必须包括:

intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
i.setData(contentUri);

我不太明白为什么我必须将从文件更改为内容,但是在此之后,文件现在又被附加了!如果您遇到此问题,请参见链接,不要忘记需要创建的新.xml.

I do not really understand why I had to change from File to Content, but after this, the file is now being attached again! See the link if you face this issue, and don't forget about the new .xml that needs to be created.

这篇关于Android将文件附加到GMAIL-无法附加空文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆