2015-11-28 3 views
0

Это мой кодКак я могу отправить изображение по электронной почте от вытяжки

String to = Tothem.getText().toString(); 
    String message = msg.getText().toString(); 
    Intent email = new Intent(Intent.ACTION_SEND); 
    email.setType("image/*"); 

    email.putExtra(Intent.EXTRA_EMAIL, new String[]{to}); 
    email.putExtra(Intent.EXTRA_TEXT, message); 
    email.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 
    Uri uri = Uri.parse("android.resource://" + getPackageName() + "/" + R.drawable.bd2); 
    email.putExtra(Intent.EXTRA_STREAM, uri); 


    email.setType("message/rfc822"); 

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

, но когда я получаю электронную почту с вне формата, я должен выбрать программу, чтобы открыть Heres how I receive the email

ответ

0

использовать мой код

 File image = new File(Uri.parse("android.resource://" + C.PROJECT_PATH + "/drawable/" + R.drawable.icon_to_share).toString()); 
     email.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(image)); 

как

 Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 
     emailIntent.setType("application/image"); 
     emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{strEmail}); 
     emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Test Subject"); 
     emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "From My App"); 

    File image = new File(Uri.parse("android.resource://" + C.PROJECT_PATH + "/drawable/" + R.drawable.icon_to_share).toString()); 

     emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(image)); 
     startActivity(Intent.createChooser(emailIntent, "Send mail...")); 
+0

Это не работает для меня –

0

Вы можете увидеть это answer.

Прежде всего, необходимо получить изображение в вытяжке папке

imageName = "planet"; 
int resourceImage = getActivity().getResources().getIdentifier(imageName, getPackageName()); 

После того, как вы должны сохранить Drawable ресурс во внутренней памяти, как SDCard.

try { 
      Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resourceImage); 
      ByteArrayOutputStream bytes = new ByteArrayOutputStream(); 
      bitmap.compress(Bitmap.CompressFormat.PNG, 50, bytes); 
      File file = new File(Environment.getExternalStorageDirectory() + File.separator + "temporal.png"); 

      boolean isCreated = file.createNewFile(); 

      FileOutputStream fileOutputStream = new FileOutputStream(file); 
      fileOutputStream.write(bytes.toByteArray()); 
      fileOutputStream.close(); 

     } catch (IOException e) { 

     } 

и, наконец, отправить изображение по электронной почте, вы должны использовать sharedintent:

Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); 
shareIntent.setType("image/png"); 
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "this is a subject"); //set your subject 
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "this is the message"); //set your message 

String imagePath = Environment.getExternalStorageDirectory() +File.separator +"temporal.png"; 
File imageFileToShare = new File(imagePath); 
Uri uri = Uri.fromFile(imageFileToShare); 
shareIntent.putExtra(Intent.EXTRA_STREAM, uri); 
startActivity(Intent.createChooser(shareIntent, "Share image")); 
Смежные вопросы