问题描述
我尝试让我的Android应用程序发送一封电子邮件,XML文件作为attachement。所有的工作除了事实,我收到的XML文件是空的罚款。我检查,以确保该文件不是空的我的手机上......
im trying to make my android application send an email with an xml file as attachement. All is working fine except for the fact that the xml file I receive is empty. I checked to make sure the file isn't empty on my phone...
下面是code我用它来发送邮件:
Here is the code I use to send the mail:
Intent mailIntent = new Intent(Intent.ACTION_SEND);
mailIntent.setType("text/Message");
mailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] {"[email protected]"});
mailIntent.putExtra(Intent.EXTRA_SUBJECT, "MySubject");
mailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file///sdcard/rapport.xml"));
startActivity(Intent.createChooser(mailIntent, "Send it out!"));
日Thnx提前!
Thnx in advance!
推荐答案
我想可能是你的文件协议,声明在那里。你可以可尝试的 Uri.fromFile 的,或者只是用文件:///(你似乎缺少冒号,除非那这里只是一个错字)。
I think it might be your file protocol declaration there. You could either try Uri.fromFile, or maybe just use "file:///" (yours appears to be missing the colon, unless that's just a typo here).
的)
另外,我的是接近你的,但是这是我如何在过去做了它(和它似乎工作):
Also, mine is close to yours, but this is how I have done it in the past (and it seems to work):
File f = new File("path_to_file");
if (f.exists() && f.canRead()) {
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" +
f.getAbsolutePath()));
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "SUBJECT");
sendIntent.putExtra(Intent.EXTRA_TEXT, "BODY");
startActivity(Intent.createChooser(sendIntent, "Email:"));
} else {
Toast.makeText(Main.this, getString(R.string.fileNotExistBlah),
Toast.LENGTH_LONG).show();
}
这篇关于发送XML文件作为与Android附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!