我已经创建了文件 myown.txt,从文件 explorer.path 中查看它是 data->data->com.contacts->files->myown.txt.我想发送包含联系人详细信息的文件作为我的电子邮件 ID 的附件我的代码是这样的:
btn=(按钮)findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
sendEmail();
}
public void sendEmail(){
String strfile = Environment.getExternalStorageDirectory().getAbsolutePath()+"/sdcard/myown.txt";
File f=new File(Environment.getExternalStorageState(),strfile);
EditText textTo =(EditText)findViewById(R.id.editTextTo);
EditText textSubject =(EditText)findViewById(R.id.editTextSubject);
TextView tv=(TextView)findViewById(R.id.textView1);
if(!textTo.getText().toString().trim().equalsIgnoreCase("")){
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{ textTo.getText().toString()});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, textSubject.getText());
//emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, tv.getText());
emailIntent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(f));
ContactsbackupActivity .this.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
}
else{
Toast.makeText(getApplicationContext(), "Please enter an email address..", Toast.LENGTH_LONG).show();
}
}
});
working on android 2.2. i can only get the textview in email but not the file. so please do let me know how to solve this problem.thanking you