0

我已经创建了文件 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
4

1 回答 1

0

嘿,它起作用了,我不知道如何。我在一个系统中开发了程序,我在另一个系统上执行。配置有一些变化,这就是它显示错误的原因。谢谢很多。hv 美好的一天

于 2012-09-13T18:22:24.277 回答