【问题标题】:Multiple Photo not sending to gmail using Intent多张照片未使用 Intent 发送到 gmail
【发布时间】:2013-08-14 06:51:39
【问题描述】:

我是 android 新手,正在尝试使用 Intent 将多个文件发送到 gmail。但它不发送附件。请帮帮我。

下面是我的代码:

Intent targetedShare = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
        targetedShare.setType("image/*"); // put here your mime type

        targetedShare.putExtra(Intent.EXTRA_SUBJECT, "Amplimesh Photo");
        targetedShare.putExtra(Intent.EXTRA_TEXT,"Attached the Quote");

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

        //Fetching the Installed App and open the Gmail App.
        for(int index = 0; index < productList.size(); index++) {
            ByteArrayInputStream byteInputStream = new ByteArrayInputStream(productList.get(index).getOverlayBitmap());
            Bitmap overLayBitmap = BitmapFactory.decodeStream(byteInputStream);

            String fileName = SystemClock.currentThreadTimeMillis() + ".png";

            //Save the bitmap to cache.
            boolean isSaved = Helper.saveImageToExternalStorage(overLayBitmap, getApplicationContext(), fileName);
            if(isSaved)
                uris.add(Uri.fromFile(new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/amplimesh", fileName)));
        }
        targetedShare.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
        startActivityForResult(Intent.createChooser(targetedShare, "Sending multiple attachment"), 12345);

【问题讨论】:

标签: android


【解决方案1】:

更新

尝试像这样的完整路径

uris.add(Uri.fromFile(new File(Environment.getExternalStorageDirectory()+"/foldername/certi/qualifications.jpg")));

使用这个

Intent share = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE); 

而不是

Intent share = new Intent(android.content.Intent.ACTION_SEND);

试试这个

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

            ArrayList<String> fileList = new ArrayList<String>();
            fileList.add(Environment.getExternalStorageDirectory()+"/foldername/certi/qualifications.jpg");
            fileList.add(Environment.getExternalStorageDirectory()+"/foldername/certi/certificate.jpg");
            fileList.add(Environment.getExternalStorageDirectory()+"/foldername/Aa.pdf");

            ArrayList<Uri> uris = new ArrayList<Uri>();
            //convert from paths to Android friendly Parcelable Uri's

            for (int i=0;i<fileList.size();i++)
            {
                File fileIn = new File(fileList.get(i));
                Uri u = Uri.fromFile(fileIn);
                uris.add(u);
            }

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

【讨论】:

  • 我已经用新代码更新了这个问题。但它仍然无法正常工作。当它打开 Gmail 应用程序时,它会显示附件,但不会发送附件。
  • 我不知道为什么我们必须使用这样的图像路径..但​​它也适用于我:)
【解决方案2】:

这是我们项目中的示例工作代码

ArrayList<Uri> imageUris = new ArrayList<Uri>();
imageUris.add(Uri.fromFile(new File("/mnt/sdcard/Medplann/IMG.jpg"))); // Add your image URIs here
imageUris.add(Uri.fromFile(new File("/mnt/sdcard/Medplann/Report.pdf")));

Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUris);
shareIntent.setType("image/*");
startActivity(Intent.createChooser(shareIntent, "Share images to.."));

【讨论】:

    【解决方案3】:

    尝试以下我在我的一个项目中用于多个附件的代码。

    public static void sendEmailWithMultipleAttachment(Context context,
            String caption, ArrayList<String> fileList) {
        Intent emailIntent = new Intent(
                android.content.Intent.ACTION_SEND_MULTIPLE);
        emailIntent.setType("application/octet-stream");
        emailIntent.setType("message/rfc822"); // use from live device
    
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, caption);
    
        ArrayList<Uri> uris = new ArrayList<Uri>();
    
        for (String file : fileList) {
            File fileIn = new File(file);
            Uri u = Uri.fromFile(fileIn);
            uris.add(u);
        }
        emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
        context.startActivity(Intent.createChooser(emailIntent,
                "Select email application."));
    }
    

    这里,ArrayList&lt;String&gt; fileList 将是图像或任何文件的路径数组。

    【讨论】:

    • 我也试过你的代码。我已经用新代码更新了这个问题。但它仍然无法正常工作。当它打开 Gmail 应用程序时,它会显示附件,但不会发送附件。
    • @user2601652,嗯...您没有在arraylist中传递完整路径..这是我朋友的问题。这就是为什么我在想为什么我的代码没有运行??? :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-30
    相关资源
    最近更新 更多