2013-02-11 38 views
0
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 
     emailIntent.setType("image/jpg"); 
     emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] 
     {"[email protected]"}); 
     emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, 
     "Test Subject"); 
     emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, 
     "go on read the emails"); 
     Log.v(getClass().getSimpleName(), "sPhotoUri=" + Uri.parse("file:///sdcard/2944154479.jpg")); 
     emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/2944154479.jpg")); 
     startActivity(Intent.createChooser(emailIntent, "Send mail...")); 

我用上面的代码的图像发送到电子邮件,电子邮件页面显示该文件附加 但我只得到了消息,附件是没有得到我的邮件。附加的图像是没有得到到邮件

请帮助 在此先感谢

回答

0

请尝试以下代码,它会为你工作。

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 
      emailIntent.setType("jpeg/image"); 
      emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, 
         new String[] { "" }); 
      emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "subject"); 
      Date cal = Calendar.getInstance().getTime(); 
      emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "body"); 

      Uri uri = Uri.fromFile(new File(Environment 
         .getExternalStorageDirectory(), "/HB.jpg")); 

      emailIntent.putExtra(Intent.EXTRA_STREAM, uri); 
      emailIntent.setType("text/plain"); 

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

它不工作,我有没有需要添加任何其他 – user1891910 2013-02-11 10:58:28

+0

你得到任何错误? – Hasmukh 2013-02-11 11:00:06

+0

不,在发送电子邮件时显示它已附加,但是当我发送并检查我的邮件时,它没有收到。 – user1891910 2013-02-11 11:04:03

0

您首先必须将类型设置为text/plain以添加您的消息。然后,您将类型设置为jpeg/image以添加图像。否则你的信息将被误解。

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,getResources().getString(R.string.emlSendToFriendSubject)); 
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[]{emailto}); 
    emailIntent.setType("text/plain"); 
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,getResources().getString(R.string.emlSendToFriendBody)); 
    File file = getFileStreamPath(EMAIL_TEMP_FILE); 
    emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 
    emailIntent.setType("image/jpeg"); 
    emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+file.getAbsolutePath())); 
    startActivityForResult(Intent.createChooser(emailIntent, getResources().getString(R.string.btnSendToFriend)),ActMain.EMAIL_DONE); 
0

试试这个:)

String path = ...; 

//Need to remove file:////, it has to be something like this storage/emulated/0/repertory/image.jpg 
if(path.startsWith("file")){ 
    path = path .replace("file:////", ""); 
} 

Intent i = new Intent(Intent.ACTION_SEND); 
i.setType("message/rfc822"); 
i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(path))); 
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"[email protected]"}); 
i.putExtra(Intent.EXTRA_SUBJECT, "Subject"); 
i.putExtra(Intent.EXTRA_TEXT , "body"); 
startActivity(Intent.createChooser(i, "Sending email..."));