2010-11-08 71 views
2

即时通讯尝试使我的android应用程序发送一封电子邮件与xml文件作为附件。除了我收到的XML文件是空的,所有工作都很好。我检查,以确保该文件不是我的手机上的空...发送一个xml文件作为附件与Android

这里是我用来发送邮件代码:

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提前!

回答

4

我认为这可能是你的文件协议声明。你可以试试Uri.fromFile,或者可能只是使用“file:///”(你似乎缺少冒号,除非这里只是一个错字)。

http://developer.android.com/reference/android/net/Uri.html#fromFile(java.io.File

而且,我的是接近你的,但是这是我如何在过去做了(这似乎工作):

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(); 
    } 
+1

日Thnx查理,失踪冒号WASN这里只是一个错字:( 我会在未来发布问题之前更仔细地阅读我的代码,而不是更少,你仍然保存我的一天! – BadSkillz 2010-11-08 18:47:19