как отправить электронное письмо с прикрепленным файлом в Android

Я создал файл myown.txt, просмотрел его из файла explorer.path: data->data->com.contacts->files->myown.txt. Я хотел отправить этот файл, содержащий контактную информацию, в виде вложения к моему электронному идентификатору мой код такой:

btn=(Button)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

person nagesh    schedule 21.08.2012    source источник


Ответы (1)


эй, это сработало, я не знаю, как. Я разработал программу в одной системе, и я выполнял ее в другой. Есть некоторые различия в конфигурации, поэтому она показывает ошибку.

person nagesh    schedule 13.09.2012