2015-01-20 3 views
-1

Это мой электронный onclick код -listner:как отправить вложение электронной почты в андроиде

private void sendEmail(){ 

Intent emailIntent = new Intent(Intent.ACTION_SENDTO); 
emailIntent.setData(Uri.parse("mailto:" + "[email protected]")); 
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "My email's subject"); 
emailIntent.putExtra(Intent.EXTRA_TEXT, "My email's body"); 

try { 
    startActivity(Intent.createChooser(emailIntent, "Send email using...")); 
} catch (android.content.ActivityNotFoundException ex) { 
    Toast.makeText(Activity.this, "No email clients installed.", Toast.LENGTH_SHORT).show(); 
} 

} 

Как я могу отправить вложение из папки, которая находится в SDCard?

+0

При передаче файла, то вам нужно передать '' Uri объект как 'EXTRA_STREAM'. Поэтому вам нужно получить к нему доступ через Uri uri = Uri.parse (новый файл (yourFilePath)) и нужно использовать 'emailIntent.putExtra (Intent.EXTRA_STREAM, uri);' – Piyush

+0

Пожалуйста, обратитесь к этой ссылке [Ссылка] (http: //stackoverflow.com/questions/14457457/android-intent-send-an-email-with-image-attachment) – droidd

ответ

-1

попытка ниже кода

public void clickbutton(View v) { 
try { 
strFile = Environment.getExternalStorageDirectory() 
.getAbsolutePath() + "/temp"; 

File file = new File(strFile); 
if (!file.exists()) 
file.mkdirs(); 
strFile = strFile + "/report.html"; 
createFile(); 
// 
Log.i(getClass().getSimpleName(), "send task - start"); 
// 
final Intent emailIntent = new Intent(
android.content.Intent.ACTION_SEND); 
// 
address = "[email protected]"; 
subject = "Recite"; 
emailtext = "Please check the attached recite"; 
// 
emailIntent.setType("plain/text"); 

emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, 
new String[] { address }); 

emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject); 

emailIntent.putExtra(Intent.EXTRA_STREAM, 
Uri.parse("file://" + strFile)); 

emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailtext); 

this.startActivity(Intent 
.createChooser(emailIntent, "Send mail...")); 

} catch (Throwable t) { 
Toast.makeText(this, "Request failed: " + t.toString(), 
Toast.LENGTH_LONG).show(); 
} 
}public void clickbutton(View v) { 
try { 
strFile = Environment.getExternalStorageDirectory() 
.getAbsolutePath() + "/temp"; 

File file = new File(strFile); 
if (!file.exists()) 
file.mkdirs(); 
strFile = strFile + "/report.html"; 
createFile(); 
// 
Log.i(getClass().getSimpleName(), "send task - start"); 
// 
final Intent emailIntent = new Intent(
android.content.Intent.ACTION_SEND); 
// 
address = "[email protected]"; 
subject = "Recite"; 
emailtext = "Please check the attached recite"; 
// 
emailIntent.setType("plain/text"); 

emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, 
new String[] { address }); 

emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject); 

emailIntent.putExtra(Intent.EXTRA_STREAM, 
Uri.parse("file://" + strFile)); 

emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailtext); 

this.startActivity(Intent 
.createChooser(emailIntent, "Send mail...")); 

} catch (Throwable t) { 
Toast.makeText(this, "Request failed: " + t.toString(), 
Toast.LENGTH_LONG).show(); 
} 
} 

и имеют вид на эту ссылку http://www.codeproject.com/Tips/268122/Send-email-with-attachment-by-android

+0

Привет Анджали, вы проверили этот код в конце? Это работает? Посмотрите, что делает код и какой вопрос задают. – droidd