我正在創建一個應用程序,但我有問題。在我將一些數據插入名爲「message.txt」的文件後,我無法通過電子郵件發送此文件,因爲我的智能手機說「不可能發送附件」。我該如何解決這個問題?Java:發送電子郵件附件:無法發送附件
這是代碼:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String address = ...
byte[] messagetosend = ...
String filename = "message.txt";
File file = new File(getExternalFilesDir(null), filename);
FileOutputStream outputstream;
try {
outputstream = openFileOutput(filename,MODE_WORLD_READABLE);
outputstream.write(messagetosend);
outputstream.flush();
outputstream.getFD().sync();
outputstream.close();
} catch (Exception e1) {
e1.printStackTrace();
}
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{address});
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
sendIntent.setType("*/*");
startActivity(Intent.createChooser(sendIntent,"Send with..."));
}
是文件名,路徑correct.You有權限讀取文件? – xyz
我怎樣才能讓文件讀取? –