以编程方式无法在多个附件中发送电子邮件

问题描述:

我无法使用Intent选择器在Android中使用多个附件发送电子邮件。从选择器中选择gmail后,它抛出不幸的是gmail已停止错误。我不会犯我犯过什么错误。谁能帮我?以编程方式无法在多个附件中发送电子邮件

final Intent ei = new Intent(Intent.ACTION_SEND_MULTIPLE); 
             ei.setType("plain/text"); 
             ei.putExtra(Intent.EXTRA_EMAIL, new String[] {"[email protected]"}); 
             ei.putExtra(Intent.EXTRA_SUBJECT, "SFC App Equiry"); 
             ei.putExtra(android.content.Intent.EXTRA_TEXT,Html.fromHtml("<b>"+"Packing Date"+"</b>&nbsp;"+pdate+"<br><b>"+"Shifting Date"+"</b>&nbsp;"+sdate+"<br><b>"+"Delivery Date"+"</b>&nbsp;"+ddate+"<br><b>"+"Source city"+"</b>&nbsp;"+scity+"<br><b>"+"Destination City"+"</b>&nbsp;"+dcity+"<br><b>"+"Source Property Type"+"</b>&nbsp;"+stprop+"<br><b>"+"Destination Property Type"+"</b>&nbsp;"+dtprop)); 

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

            //uris.parse("file://sdcard/Images/20140812_130215.jpg"); 
            //uris.add("file://sdcard/Images/20140812_130227.jpg"); 

            File fileIn = new File(ppath); 
            File fileIn1 = new File(ppath1); 
            File fileIn2 = new File(ppath2); 
            File fileIn3 = new File(ppath3); 
            File fileIn4 = new File(ppath4); 
            File fileIn5 = new File(ppath5); 
            File fileIn6 = new File(ppath6); 

            Uri u = Uri.fromFile(fileIn); 
            Uri u1 = Uri.fromFile(fileIn1); 
            Uri u2 = Uri.fromFile(fileIn2); 
            Uri u3 = Uri.fromFile(fileIn3); 
            Uri u4 = Uri.fromFile(fileIn4); 
            Uri u5 = Uri.fromFile(fileIn5); 
            Uri u6 = Uri.fromFile(fileIn6); 

            uris.add(u); 
            uris.add(u1); 
            uris.add(u2); 
            uris.add(u3); 
            uris.add(u4); 
            uris.add(u5); 
            uris.add(u6); 



            ei.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); 
            startActivityForResult(Intent.createChooser(ei, "Sending multiple attachment"), 12345); 

我的堆栈跟踪是:

11-26 10:58:41.791: W/Bundle(19728): Key android.intent.extra.TEXT expected ArrayList<CharSequence> but value was a java.lang.String. The default value <null> was returned. 
11-26 10:58:41.801: W/Bundle(19728): Attempt to cast generated internal exception: 
11-26 10:58:41.801: W/Bundle(19728): java.lang.ClassCastException: java.lang.String cannot be cast to java.util.ArrayList 
11-26 10:58:41.801: W/Bundle(19728): at android.os.Bundle.getCharSequenceArrayList(Bundle.java:1367) 
11-26 10:58:41.801: W/Bundle(19728): at android.content.Intent.getCharSequenceArrayListExtra(Intent.java:5265) 
11-26 10:58:41.801: W/Bundle(19728): at android.content.Intent.migrateExtraStreamToClipData(Intent.java:7843) 
11-26 10:58:41.801: W/Bundle(19728): at android.content.Intent.migrateExtraStreamToClipData(Intent.java:7810) 
11-26 10:58:41.801: W/Bundle(19728): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1423) 
11-26 10:58:41.801: W/Bundle(19728): at android.app.Activity.startActivityForResult(Activity.java:3547) 
11-26 10:58:41.801: W/Bundle(19728): at android.app.Activity.startActivityForResult(Activity.java:3508) 
11-26 10:58:41.801: W/Bundle(19728): at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:840) 
11-26 10:58:41.801: W/Bundle(19728): at com.ipot.setringtone.MainActivity.onCreate(MainActivity.java:131) 
11-26 10:58:41.801: W/Bundle(19728): at android.app.Activity.performCreate(Activity.java:5484) 
11-26 10:58:41.801: W/Bundle(19728): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093) 
11-26 10:58:41.801: W/Bundle(19728): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2400) 
11-26 10:58:41.801: W/Bundle(19728): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2498) 
11-26 10:58:41.801: W/Bundle(19728): at android.app.ActivityThread.access$900(ActivityThread.java:179) 
11-26 10:58:41.801: W/Bundle(19728): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1324) 
11-26 10:58:41.801: W/Bundle(19728): at android.os.Handler.dispatchMessage(Handler.java:102) 
11-26 10:58:41.801: W/Bundle(19728): at android.os.Looper.loop(Looper.java:146) 
11-26 10:58:41.801: W/Bundle(19728): at android.app.ActivityThread.main(ActivityThread.java:5641) 
11-26 10:58:41.801: W/Bundle(19728): at java.lang.reflect.Method.invokeNative(Native Method) 
11-26 10:58:41.801: W/Bundle(19728): at java.lang.reflect.Method.invoke(Method.java:515) 
11-26 10:58:41.801: W/Bundle(19728): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1288) 
11-26 10:58:41.801: W/Bundle(19728): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1104) 
11-26 10:58:41.801: W/Bundle(19728): at dalvik.system.NativeStart.main(Native Method) 
11-26 10:58:42.431: W/ResolverActivity(19728): mLaunchedFromPackage=com.ipot.setringtone 
11-26 10:58:42.781: I/DVFSHelper(19728): DVFSHelper:: failed to load CFMS 
11-26 10:58:42.781: I/DVFSHelper(19728): DVFSHelper:: failed to load CFMS 
11-26 10:58:42.781: I/DVFSHelper(19728): DVFSHelper:: failed to load CFMS 
11-26 10:58:42.781: I/DVFSHelper(19728): DVFSHelper:: failed to load CFMS 
11-26 10:58:42.901: I/Choreographer(19728): Skipped 38 frames! The application may be doing too much work on its main thread. 
11-26 10:58:43.001: D/OpenGLRenderer(19728): Enabling debug mode 0 
11-26 10:58:47.641: D/AbsListView(19728): onDetachedFromWindow 
+0

你可以把你的日志 – 2014-11-25 12:08:56

+0

请发布你的stacktrace。 – 2014-11-25 12:17:22

+0

11-25 16:40:09.855:W/IconCustomizer(17966):无法加载transform_config.xml 11-25 16:40:09.975:W/Bundle(17966):键android.intent.extra.TEXT预期ArrayList 但值是一个java.lang.String。默认值已返回。11-25 16:40:09.985:W/Bundle(17966):尝试投射生成的内部异常: 11-25 16:40:09.985:W/Bundle(17966):java.lang .ClassCastException:无法将java.lang.String强制转换为java.util.ArrayList11-25 16:40:09.985:W/Bundle(17966):\t at android.os.Bundle.getCharSequenceArrayList(Bundle.java:1331) – Divya 2014-11-25 12:23:51

我没有改变任何代码。但今天运行后,它的工作完美。不知道哪一个错误或正确。无论如何,现在它对我来说工作得很好,我发布了相同的代码。谢谢Alok Nair提供这样的帮助。

+0

HI @Divya可以请你帮我我试图共享文本有多个图像,但我得到这个错误“键android.intent.extra.TEXT预期的ArrayList ,但值是java.lang.String。返回的默认值”。 我看到你面临同类问题,如果你能解决我的问题,那么请给出答案。 这里是我的问题http://*.com/questions/38293853/using-intent-share-text-with-multiple-image-in-android] – Subho 2016-07-10 16:10:30

您可以用下面的代码发送邮件上多个附件:

public boolean sendEmailWithMultipleAttachments(Context context, 
                 String[] emailTo, String[] emailCC, String[] emailBCC, 
                 String subject, String emailBody, List filePaths) throws ActivityNotFoundException { 

      final Intent emailIntent = 
        new Intent(android.content.Intent.ACTION_SEND_MULTIPLE); 
      emailIntent.setType("message/rfc822"); 
      emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, emailTo); 
      emailIntent.putExtra(android.content.Intent.EXTRA_CC, emailCC); 
      emailIntent.putExtra(android.content.Intent.EXTRA_BCC, emailBCC); 
      emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject); 
      ArrayList<String> extra_text = new ArrayList<String>(); 
      extra_text.add("Your text here"); 
      ei.putStringArrayListExtra(Intent.EXTRA_TEXT, extra_text); 

      if (filePaths != null) { 
       // has to be an ArrayList 
       ArrayList uris = new ArrayList(); 
       // convert from paths to Android friendly Parcelable Uri's 
       for (String file : filePaths) { 
        File fileIn = new File(file); 
        if (fileIn.exists()) { 
         Uri u = Uri.fromFile(fileIn); 
         uris.add(u); 
        } 
       } 
       emailIntent.putParcelableArrayListExtra 
         (Intent.EXTRA_STREAM, uris); 
      } 
      context.startActivity(Intent.createChooser(emailIntent, "Sent mail")); 
      return true; 
     } 
+0

HI @Alok可以请你帮我,我正在尝试与多个图像共享文本,但我得到这个错误“键android.intent.extra.TEXT预期的ArrayList ,但价值是java.lang中.String。返回默认值。“ 这里是我的问题http://*.com/questions/38293853/using-intent-share-text-with-multiple-image-in-android] – Subho 2016-07-10 16:08:58