1

我正在尝试将电子邮件中的附件作为 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());
    }     
}

}

4

0 回答 0