安卓系统:通过ImageView发送带有图像的电子邮件



我是stackoverflow的新手。我的Android应用程序有点问题,尤其是ImageView,它会在点击时触发事件。此事件打开一个带有一些预先写好的文本的电子邮件客户端,它应该附加图像的图像。我已经知道图像之前应该转换成位图,然后压缩并发送到电子邮件客户端,但不幸的是,我不是Android/Java专家,所以我找不到如何做到这一点。这是电子邮件方法的代码:

下方的新代码

其中,我必须将"StringimageURI=null;"替换为电子邮件所需的图像。谢谢大家!

编辑:

我设法把我的代码编辑成这样,没有错误:

public void sendMail(ImageView image){
    Intent i = new Intent(Intent.ACTION_SEND);
    int imageURI = R.drawable.img1;
    i.setType("text/plain");
    i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"destinatario@globelife.biz"});
    i.putExtra(Intent.EXTRA_SUBJECT, "Oggetto");
    i.putExtra(Intent.EXTRA_TEXT   , "Globelife");
    i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    i.setType("image/jpeg");
    i.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.resource://"+getPackageName()+"/"+imageURI));

    try {
        startActivity(Intent.createChooser(i, "Send mail..."));
    } catch (android.content.ActivityNotFoundException ex) {
        Toast.makeText(Test01Activity.this, "Non sono presenti app per l'invio di e-mails.", Toast.LENGTH_SHORT).show();
    }
}

但我需要将"int imageURI=R.drawable.img1;"更改为"int imageURI=ImageView.src;"或类似的内容

尝试这个

ImageView iv = (ImageView) findViewById(R.id.splashImageView);
Drawable d =iv.getBackground();
BitmapDrawable bitDw = ((BitmapDrawable) d);
Bitmap bitmap = bitDw.getBitmap();
File  mFile = savebitmap(bitmap);

然后

   Uri u = null;
   u = Uri.fromFile(mFile);
   Intent emailIntent = new Intent(Intent.ACTION_SEND);
   emailIntent.setType("image/*");
   emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Hello...");
   // + "nr" + "nr" +
   // feed.get(Selectedposition).DETAIL_OBJECT.IMG_URL
   emailIntent.putExtra(Intent.EXTRA_TEXT, "Your tsxt here");
   emailIntent.putExtra(Intent.EXTRA_STREAM, u);
   startActivity(Intent.createChooser(emailIntent, "Send email..."));

和CCD_ 1方法

    private File savebitmap(Bitmap bmp) {
  String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
  OutputStream outStream = null;
  File file = new File(extStorageDirectory, temp + ".png");
  if (file.exists()) {
   file.delete();
   file = new File(extStorageDirectory, temp + ".png");
  }
  try {
   outStream = new FileOutputStream(file);
   bmp.compress(Bitmap.CompressFormat.PNG, 100, outStream);
   outStream.flush();
   outStream.close();
  } catch (Exception e) {
   e.printStackTrace();
   return null;
  }
  return file;
 }
Intent i = new Intent(Intent.ACTION_SEND);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setType("image/jpg");
i.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/Pictures/
image.jpg"));
startActivity(i);
Intent intent=new Intent(Intent.ACTION_SEND);
String[] recipients={"destinatario@domain.com"};
intent.putExtra(Intent.EXTRA_EMAIL, recipients);
intent.putExtra(Intent.EXTRA_SUBJECT, "Oggetto");
intent.putExtra(Intent.EXTRA_TEXT   , "Testo");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setType("image/png");
intent.putExtra(Intent.EXTRA_STREAM,Uri.parse(“file///sdcard/Images/your_image.jpg”));//or you can pass the path of your image
startActivity(Intent.createChooser(intent, "Send mail"));

//重新移动String imageURI=null;

public void sendMail(ImageView image){
    Intent i = new Intent(Intent.ACTION_SEND);
Uri pngImageUri = Uri.parse(image);

i.setType("image/png");//change here with image/png
    i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"destinatario@domain.com"});
    i.putExtra(Intent.EXTRA_SUBJECT, "Oggetto");
    i.putExtra(Intent.EXTRA_TEXT   , "Testo");
    i.putExtra(Intent.EXTRA_STREAM, pngImageUri);

相关内容

  • 没有找到相关文章

最新更新