安卓:通过Gmail分享的zip文件 [英] Android: Share zip file via Gmail
问题描述
我工作的一个Android应用程序应该允许用户通过Gmail他们的内容。我使用的是Android版本2.2(升级Froyo)。
问题是,我找不到这方面的任何工作的解决方案,我想几乎所有的东西,但没有运气。
这是code我使用的是:
I'm working on an Android application that should allow the users to share their content via Gmail. I'm using android version 2.2(Froyo). The problem is that I can't find any working solution for this, I tried almost everything ,but with no luck. this is the code I'm using:
Intent sharingIntent = new Intent(Intent.ACTION_SEND);;
sharingIntent.setType("application/zip");
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
getString(R.string.share_subject));
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, getString(R.string.share_body));
String zipFile = FileProvider.URI_AUTHORITY + File.separator + mItemSelected.getLibraryName() + File.separator + mItemSelected.getZipFileName();
sharingIntent.putExtra(Intent.EXTRA_STREAM, android.net.Uri.parse(zipFile));
startActivity(Intent.createChooser(sharingIntent, (getString(R.string.share_chooser))));
}
在这种情况下,问题是,Gmail应用程序,没有明显的理由,被替换文件的MIME类型和显示文件为text / html,然后我的应用程序没有在应用程序列表可以显示对付这种类型的文件。另一个限制是,我不希望使用text / html的在我的意图过滤器,因为我希望它集中尽可能多的,而且如果有可能我会定义自己的MIME类型...
The problem in this case is that the Gmail app, for no obvious reason, is replacing the mime type of the file, and show the file as text/html, and then my application is not shown in the application list that can deal with this kind of file. Another restriction is that I don't want to use text/html in my intent filter, because I want it to be focused as much as possible, and if it were possible I would define my own mime type...
我做了一些研究,发现此<一个href=\"http://stackoverflow.com/questions/6583217/which-mime-type-to-use-to-attach-zip-file-in-gmail\">question,但没有答案......
I did a little research and found this question, but with no answers...
更多的MIME类型我尝试:
More mime types I tried:
application/x-compressed, application/x-zip-compressed
multipart/x-zip and application/octet-stream
有没有这个问题?
Is there any solution for this problem ??
感谢。
推荐答案
很多的麻烦后,我发现Gmail中,通过意向推出,不喜欢它的附件preFIX名为.zip。
所以,我成功地将其改名.vip后发送附件。
这里是一块code的(不过outFile是改名为.vip一个压缩文件):
after a lot of trouble, I discovered that Gmail, launched via Intent, does not like attachments whose prefix is .zip. So, I succeeded in sending the attachments after renaming it ".vip". Here is a piece of code (outFile is a zipped file renamed as ".vip"):
enter
private void sendMail(File outFile) {
Uri uriToZip = Uri.fromFile(outFile);
String sendText = "Dear friend,\n\n...";
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
new String[] { "checcodotti@gmail.com" });
sendIntent.putExtra(android.content.Intent.EXTRA_TEXT, sendText);
sendIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Log of the test " + expFilename);
// sendIntent.setType("image/jpeg");
// sendIntent.setType("message/rfc822");
sendIntent.setType("*/*");
sendIntent.putExtra(android.content.Intent.EXTRA_STREAM, uriToZip);
startActivity(Intent.createChooser(sendIntent, "Send Attachment !:"));
}
请让我知道如果它帮助。
商祺
FD
Please let me know if it helps. Regards FD
这篇关于安卓:通过Gmail分享的zip文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!