我正在尝试将来自电子邮件的附件作为csv文件从模拟器发送。电子邮件已发送但没有附件。它也给了我一个祝酒消息“文件大到附加”
公共类MainActivityActivity扩展了Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
String dir = "/Android/data/com.pucit/csv/";
String fullDir = Environment.getExternalStorageDirectory().toString() + dir;
generateCsvFile(fullDir, "data.csv");
Uri uri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(),"data.csv"));
Log.d("321", "a"+uri.toString());
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"ninja9196@gmail.com"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Attachment");
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///mnt/sdcard/data.csv"));
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "gmail.com");
MainActivityActivity.this.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
}
private static void generateCsvFile(String dir, String fileName) {
try {
File theDir = new File(dir);
theDir.mkdirs();
FileWriter writer = new FileWriter(dir + fileName);
writer.append("DisplayName");
//generate whatever data you want
writer.flush();
writer.close();
} catch (IOException e) {
Log.i("file", e.getMessage());
}
}
}