1

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

下面的新代码

我必须替换“String imageURI = 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;” 或类似的东西

4

4 回答 4

6

尝试这个

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...");
   // + "\n\r" + "\n\r" +
   // 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..."));

savebitmap方法

    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;
 }
于 2012-07-11T09:27:33.147 回答
0
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"));
于 2012-07-11T08:19:35.687 回答
0
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);
于 2012-07-11T08:21:21.097 回答
-1

//去除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);
于 2012-07-11T08:16:07.750 回答