1

첨부 파일이있는 메일을 보내려고합니다. 제대로 작동하는 코드를 작성했지만 여기서 프로그램에 첨부 할 파일 이름을 작성했습니다. 원하지 않습니다. 이렇게 나는 그것을 sdcard에서 사용자가 선택하고 싶습니다. 어떻게 해야할지.첨부 파일을 이메일에 추가하려면

public class DemoVoiceActivity extends Activity { 
     EditText txtTo,mSubject,mMessageBody,attachment; 
     String strSubject,strMessageBody; 
     /** Called when the activity is first created. */ 
     @Override 
     public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.main); 
      txtTo = (EditText)findViewById(R.id.to); 

     mSubject = (EditText)findViewById(R.id.subject); 
     mMessageBody = (EditText)findViewById(R.id.message_content); 
     attachment=(EditText)findViewById(R.id.attachment); 

     String[] strTo = {txtTo.getText().toString()}; 

     strSubject = mSubject.getText().toString(); 
     strMessageBody = mMessageBody.getText().toString(); 
     Intent objIntent = new Intent(android.content.Intent.ACTION_SEND); 
     objIntent.putExtra(android.content.Intent.EXTRA_EMAIL, strTo); 

     objIntent.setType("plain/text"); objIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, strSubject); 
     objIntent.putExtra(android.content.Intent.EXTRA_TEXT, "MESSAGE"); objIntent.putExtra(android.content.Intent.EXTRA_STREAM,Uri.parse("file://"+Environment.getExternalStorageDirectory()+"/q.mp4")); 
     startActivity(objIntent); 
     finish(); 
    } 
} 

답변

1

체크 아웃 https://stackoverflow.com/a/7857102/975959

그는 간단한 파일 츄 - 오픈 소스 라이브러리를 provied이 답변을. 그런 다음 onFileSelect() 메서드에서 파일 경로를 가져 와서 objIntent에 추가 할 수 있습니다.

그는 그렇게하고 싶다면 직접 구현하는 방법을 제공합니다.

관련 문제