添付ファイル付きのメールを送信する次のコードを試しました。送信しようとすると添付ファイルが表示されますが、問題は、件名と本文が含まれ、添付ファイルがない電子メールのみを送信することです。私はあなたの助けに感謝します
emailButton = (Button) findViewById(R.id.emailButton);
textTo = (EditText) findViewById(R.id.txtenterserial);
textSubject = (EditText) findViewById(R.id.txtenterseri);
textMessage = (EditText) findViewById(R.id.txtenters);
emailButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String to = textTo.getText().toString();
String subject = textSubject.getText().toString();
String message = textMessage.getText().toString();
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
File data = null;
try {
Date dateVal = new Date();
String filename = dateVal.toString();
data = File.createTempFile("Report", ".csv");
Log.d("vvvvvv", data.toString());
FileWriter out = (FileWriter) GenerateCsv.generateCsvFile(data, "Name,Data1");
//Log.d("SSSSHOOOOW", out.toString());
i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(data));
i.putExtra(Intent.EXTRA_EMAIL, new String[] { to });
i.putExtra(Intent.EXTRA_SUBJECT, subject);
i.putExtra(Intent.EXTRA_TEXT, message);
startActivity(Intent.createChooser(i, "E-mail"));
} catch (IOException e) {
e.printStackTrace();
}
}
});
public static class GenerateCsv {
public static FileWriter generateCsvFile(File sFileName,String fileContent) {
FileWriter writer = null;
try {
writer = new FileWriter(sFileName);
writer.append(fileContent);
writer.flush();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
writer.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return writer;
}
}
これがLogCatです
01-20 22:07:26.998: E/Trace(8471): error opening trace file: No such file or directory (2)
01-20 22:07:27.929: D/gralloc_goldfish(8471): Emulator without GPU emulation detected.
01-20 22:07:46.538: D/vvvvvv(8471): /data/data/com.example.emailandroid/cache/Report1916903470.csv
01-20 22:07:46.998: D/dalvikvm(8471): GC_CONCURRENT freed 201K, 5% free 4318K/4544K, paused 78ms+82ms, total 292ms
01-20 22:07:47.458: I/Choreographer(8471): Skipped 94 frames! The application may be doing too much work on its main thread.
01-20 22:07:51.828: W/IInputConnectionWrapper(8471): showStatusIcon on inactive InputConnection
01-20 22:07:52.718: I/Choreographer(8471): Skipped 58 frames! The application may be doing too much work on its main thread.
01-20 22:09:40.928: I/Choreographer(8471): Skipped 33 frames! The application may be doing too much work on its main thread.
どこがうまくいかなかったのか教えてください。