我是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;” 或类似的东西