2012-03-21 53 views
0

我想從資產文件夾附加多個圖像。電子郵件發送成功,但沒有獲取附加圖像。在電子郵件中顯示圖像0 kb。 我的代碼在這裏。請給出任何想法。其他任何方式發送多個圖像。在Android中的資產從電子郵件中附加多個圖像

final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE); 
     emailIntent.setType("jpeg/image"); 
     emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject); 
     emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, body); 


     ArrayList<Uri> uris = new ArrayList<Uri>(); 
     //convert from paths to Android friendly Parcelable Uri's 
     for (int i=0; i < arrImageslist.size(); i++) 
     { 
      Uri u=Uri.parse("file:///android_asset/DiseaseImages/"+arrImageslist.get(i)); 
      uris.add(u); 


     } 

     emailIntent.putParcelableArrayListExtra(android.content.Intent.EXTRA_STREAM, uris); 
     startActivity(android.content.Intent.createChooser(emailIntent, "Send mail...")); 
+0

只是嘗試將這些圖像放在SD卡上,然後附加到電子郵件意圖,看看會發生什麼? – user370305 2012-03-21 12:14:34

+0

我在資產文件夾中有圖像。我想從資產文件夾發送圖像。 – Dugs 2012-03-21 12:23:24

+0

可能是那些圖像對android電子郵件應用程序來說是不可讀的,因爲它在資產目錄中,而資產對於android應用程序是私人的。 – user370305 2012-03-21 12:28:31

回答

1

第一部分....

Intent sendIntent = new Intent(Intent.ACTION_SEND_MULTIPLE); 
sendIntent.setType("plain/text"); 
sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[] {"[email protected]"}); 
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Accident Capture"); 
sendIntent.putExtra(Intent.EXTRA_TEXT, emailBody); 

ArrayList<Uri> uriList = getUriListForImages(); 
sendIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uriList); 
Log.d(TAG, "Size of the ArrayList :: " +uriList.size()); 
FormHolderActivity.this.startActivity(Intent.createChooser(sendIntent, "Email:")); 

------------------ GetUriListForImages ---------- ----------------------

private ArrayList<Uri> getUriListForImages() throws Exception { 
      ArrayList<Uri> myList = new ArrayList<Uri>(); 
      String imageDirectoryPath = Environment.getExternalStorageDirectory().getAbsolutePath()+ "/folder/"; 
      File imageDirectory = new File(imageDirectoryPath); 
      String[] fileList = imageDirectory.list(); 
      if(fileList.length != 0) { 
       for(int i=0; i<fileList.length; i++) 
       { 
        try 
        { 
         ContentValues values = new ContentValues(7); 
         values.put(Images.Media.TITLE, fileList[i]); 
         values.put(Images.Media.DISPLAY_NAME, fileList[i]); 
         values.put(Images.Media.DATE_TAKEN, new Date().getTime()); 
         values.put(Images.Media.MIME_TYPE, "image/jpeg"); 
         values.put(Images.ImageColumns.BUCKET_ID, imageDirectoryPath.hashCode()); 
         values.put(Images.ImageColumns.BUCKET_DISPLAY_NAME, fileList[i]); 
         values.put("_data", imageDirectoryPath + fileList[i]); 
         ContentResolver contentResolver = getApplicationContext().getContentResolver(); 
         Uri uri = contentResolver.insert(Images.Media.EXTERNAL_CONTENT_URI, values); 
         myList.add(uri); 
        } catch (Exception e) { 
         e.printStackTrace(); 
        } 
       } 
      } 
      return myList; 
     } 
+0

嘗試......而不是SD卡把你的資產的代碼。 .... – kanchan 2012-03-21 13:15:23

相關問題