我在Android应用程序中捕获图像。然后我获取该图像路径并将该路径作为字符串发送到电子邮件功能。在MIME邮件中,我将该文件附加为DataSource fds = new FileDataSource(path);
我的代码是......
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i, REQ_CAMERA_IMAGE);
获取路径的活动...
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode == RESULT_OK){
//image.setImageBitmap(null);
//Uri return from external activity
URI = data.getData();
// text1.setText("Returned Uri: " + orgUri.toString() + "\n");
//path converted from Uri
convertedPath = getRealPathFromURI(URI);
// text2.setText("Real Path: " + convertedPath + "\n");
//Uri convert back again from path
uriFromPath = Uri.fromFile(new File(convertedPath));
Log.e("HAAAAAAAAAAAIIIIII", uriFromPath.toString() + "\n");
}
}
public String getRealPathFromURI(Uri contentUri) {
String[] proj = { MediaStore.Images.Media.DATA };
//This method was deprecated in API level 11
//Cursor cursor = managedQuery(contentUri, proj, null, null, null);
CursorLoader cursorLoader = new CursorLoader(
this,
contentUri, proj, null, null, null);
Cursor cursor = cursorLoader.loadInBackground();
int column_index =
cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
将图像路径作为字符串传递给电子邮件
messageBodyPart = new MimeBodyPart();
DataSource fds = new FileDataSource(path);
messageBodyPart.setDataHandler(new DataHandler(fds));
multipart.addBodyPart(messageBodyPart);
答案 0 :(得分:1)
尝试阅读文档@ https://developer.android.com/reference/android/provider/MediaStore.html#ACTION_IMAGE_CAPTURE
您必须通过额外的EXTRA_OUTPUT
才能获得缩小的图像。
了解您正在使用的API。