2016-11-27 15 views
0

電子メールの意図に写真ファイルを追加したいと思います。 意図が正常に開始しています。添付ファイルが電子メールの意図に追加されない

問題:添付ファイルが表示されません。 Gmailのアプリケーションで。エラーメッセージは表示されません。 どこに問題がありますか?

私はこのpostの提案と一緒にコードを変更しましたが、私のコードはまだ動作していないようです。

写真のオブジェクトから受け取ったファイルパス:file:///storage/emulated/0/Pictures/SMSCloudImages/IMG_20161127_121011.jpg ギャラリーに画像を表示できるので、正しいパスにする必要があります。

Uri uri = Uri.parse("mailto:" + "[email protected]") 
       .buildUpon() 
       .appendQueryParameter("subject", subject) 
       .appendQueryParameter("body", body) 
       .build(); 

     List<Photo> photoList = new ArrayList<>(); 
     photoList.addAll(databaseHandler.getPhotos(qReport.getId())); 

     Intent emailIntent = new Intent(Intent.ACTION_SENDTO, uri); 

     Intent intentPick = new Intent(); 
     intentPick.setAction(Intent.ACTION_PICK_ACTIVITY); 
     intentPick.putExtra(Intent.EXTRA_TITLE, getResources().getString(R.string.q_report_launch_mail_text)); 
     intentPick.putExtra(Intent.EXTRA_INTENT, emailIntent); 

     for (Photo photo: photoList) { 
      intentPick.putExtra(Intent.EXTRA_STREAM, Uri.parse(photo.getName())); 
     } 

     this.startActivityForResult(intentPick, REQUEST_CODE_MY_PICK); 

答えて

0

これは私が使用するコードです:

//how hany picture you want the user to upload 
private static final int SELECT_PICTURE = 1; 

public void grabImg(){ 
    Intent intent = new Intent(); 
    intent.setType("image/*"); 
    intent.setAction(Intent.ACTION_GET_CONTENT); 
    startActivityForResult(Intent.createChooser(intent, 
      "Select Picture"), SELECT_PICTURE); 
} 

Uri uri = null; 

protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) { 
    super.onActivityResult(requestCode, resultCode, imageReturnedIntent); 
     if(resultCode == RESULT_OK){ 
      Uri selectedImage = imageReturnedIntent.getData(); 
      uri = selectedImage; 

     } 
} 

//This is triggered on a button click 

String subject = Suggest.getText().toString(); 
      String rating = String.valueOf(RateBar.getRating()); 
      String to ="[email protected]"; //destination 
      String message = UserInput.getText().toString(); 
      String body = message; 
      Intent email = new Intent(Intent.ACTION_SEND); 
      email.putExtra(Intent.EXTRA_EMAIL, new String[]{to}); 
      email.putExtra(Intent.EXTRA_SUBJECT, subject); 
      email.putExtra(Intent.EXTRA_TEXT, body); 
      email.putExtra(Intent.EXTRA_STREAM, uri); 
      email.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 
      //need this to prompts email client only 
      email.setType("message/rfc822"); 

      startActivity(Intent.createChooser(email, "Choose an Email client :")); 
0

が(読み書き)のAndroidマニフェストへの適切なアクセス権を追加することを忘れないでください:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> 
関連する問題