我创建了文件myown.txt,从文件explorer.path查看它是data-> data-> com.contacts-> files-> myown.txt.i想要发送包含联系人详细信息的文件作为我的电子邮件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
答案 0 :(得分:0)