email - Android发送电子邮件的多个附件之一从drawable文件夹和 SDCard

  显示原文与译文双语对照的内容
56 4

我想发送多个附件的电子邮件解决方案,但现在问题是,我有 2个 例如 文件。 coding在发送邮件时,我同时显示两个附件但我只收到一个附件,我无法从内部文件夹中获取附件。我无法从内部文件夹 例如 进行连接。 下面是我的代码请帮我解决这个问题。


public class TransmitAgreement extends Activity{

@Override
protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_transmit_agreement);

 String addressLine = gpsTracker.getAddressLine(this);
 String emailaddress ="myemail";
 String message ="Msg"
 String subject ="sbj";

 Intent emailIntent = new Intent(
 android.content.Intent.ACTION_SEND_MULTIPLE);
 emailIntent.setType("text/plain");
 emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
 new String[] { emailaddress });
 emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
 emailIntent.putExtra(Intent.EXTRA_TEXT, message);
 ArrayList<Uri> uris = new ArrayList<Uri>();
//convert from paths to Android friendly Parcelable Uri's
 String[] filePaths = new String[] {
"android.resource://com.example.freenup/" + R.drawable.freenup_app_agreement,
"sdcard/saved_images/MyImage.png" };
 for (String file : filePaths) {
 File fileIn = new File(file);
 Uri u = Uri.fromFile(fileIn);
 uris.add(u);
 }
 emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
 startActivity(Intent.createChooser(emailIntent,"Send mail..."));
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
//Inflate the menu; this adds items to the action bar if it is present.
 getMenuInflater().inflate(R.menu.transmit_agreement, menu);
 return true;
}
}

我也尝试过其他解决方案,但遇到同样的问题。 我只是geeting里的一个附件。

时间: 原作者:

122 2

我想你不能直接从drawable文件夹发送附件

用这种方法尝试


 try
 {
 Intent email = new Intent(Intent.ACTION_SEND_MULTIPLE);
 email.setType("plain/text");
 email.putExtra(Intent.EXTRA_EMAIL, new String[] {"email id"});
 email.putExtra(Intent.EXTRA_SUBJECT,"That one works");
 FileOutputStream outStream; 
 File file;

 Bitmap bm = BitmapFactory.decodeResource( getResources(), R.drawable.ic_launcher);
 String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
 file = new File(extStorageDirectory,"ic_launcher.PNG");
 try {
 outStream = new FileOutputStream(file);
 bm.compress(Bitmap.CompressFormat.PNG, 100, outStream);
 outStream.flush();
 outStream.close();
 } catch (FileNotFoundException e) {
 e.printStackTrace();
 } catch (IOException e) {
 e.printStackTrace();
 }

 File[] f = new File[2];
 f[0] = new File("/mnt/ext_card/Download/test.jpg");
 f[1] = file;

 ArrayList<Uri> uris = new ArrayList<Uri>();

 for(int i=0;i<f.length;i++)

 {

 Uri u = Uri.fromFile(f[i]);
 uris.add(u);

 }

 email.putExtra(Intent.EXTRA_EMAIL, new String[] {"" });
 email.putExtra(Intent.EXTRA_SUBJECT,"My Subject");
 email.putExtra(Intent.EXTRA_TEXT,"");
 email.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
 startActivity(Intent.createChooser(email,"Choose an Email client :"));

 }

 catch (Exception e) {

 e.toString();

 }

原作者:
...