gpt4 book ai didi

android - 从 native 图库中选择图像并附加到电子邮件

转载 作者:行者123 更新时间:2023-11-29 00:24:10 24 4
gpt4 key购买 nike

我允许用户浏览 native 图库 > 选择图像,并尝试将所选图像附加到电子邮件,但没有得到准确的图像,请参阅我的代码:

private static int RESULT_LOAD_IMAGE = 1;
String picturePath;

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };

Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();

int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
picturePath = cursor.getString(columnIndex);
cursor.close();

// getting exact image which i selected with full path
Toast.makeText(getApplicationContext(), picturePath.toString(), Toast.LENGTH_LONG).show();

sendImage();

}
}

// to attach an image to email
public void sendImage() {
// TODO Auto-generated method stub
Intent i = new Intent(Intent.ACTION_SEND);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_STREAM, Uri.parse(picturePath));
i.putExtra(Intent.EXTRA_EMAIL, new String[]{"recepient@mail.cin"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT, "body of email");
startActivity(Intent.createChooser(i,"Send email via:"));
}
}

我错过了什么?我哪里做错了?

最佳答案

试试这个附加图片。

File file = getFileStreamPath(EMAIL_TEMP_FILE);
i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
i.setType("image/jpeg");
i.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+file.getAbsolutePath())); //Your image file

希望对您有所帮助。

关于android - 从 native 图库中选择图像并附加到电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20989855/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com