我在使用Droid X手机时遇到问题,因为我的应用程序发送了附加电子邮件。我的代码适用于所有其他Android设备,如HTC,三星galaxy,Milestone。但我只有Droid X的问题。我在SD卡中保存了我的html文件,但我无法将其附加到电子邮件中。我收到了空邮件,我没有在droid x mobile中获得附件。 在这里我附上了我的代码......
将文件保存在SD卡中:
protected void savehtml(HtmlViwer htmlViwer, String htmlcontent2,String string) {
try {
File root = new File(Environment.getExternalStorageDirectory(),"PalmAgent");
if (!root.exists()) {
root.mkdirs();
}
String sdcardhtmlpath = root.getPath().toString() + "/print.html";
FileWriter fstream = new FileWriter(sdcardhtmlpath);
BufferedWriter out = new BufferedWriter(fstream);
out.write(htmlcontent2);
out.close();
} catch (Exception e) {// Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
发送带附件的邮件:
Intent sentinIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
sentinIntent.setType("plain/text");
ArrayList<Uri> uris = new ArrayList<Uri>();
File root = new ile(Environment.getExternalStorageDirectory(), "PalmAgent");
String sdcardhtmlpath = root.getPath().toString()+ "/print.html";
String[] filePaths = new String[] { sdcardhtmlpath };
for (String file : filePaths) {
File fileIn = new File(file);
Uri u = Uri.fromFile(fileIn);
uris.add(u);
}
sentinIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
startActivity(Intent.createChooser(sentinIntent,"Send mail via"));
}
答案 0 :(得分:2)
最后我找到了解决方案......当连接到PC时,SD卡与PC共享其内存,这样我就无法访问SD卡了。而且同样的设备没有存储卡
Intent sentinIntent = new Intent(Intent.ACTION_SEND);
sentinIntent.setType("plain/text");
File root = new ile(Environment.getExternalStorageDirectory(), "Path");
String sdcardhtmlpath = root.getPath().toString()+ "/print.html";
String[] filePaths = new String[] { sdcardhtmlpath };
uris = getURI(filePaths );
sentinIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
startActivity(Intent.createChooser(sentinIntent,"Send mail via"));
}