void take_photo() {
File file = null;
try {
file = PhotoUtils.createTemporaryFile("picture", ".jpg",
EditProfileActivity.this);
file.delete();
} catch (Exception e) {
e.printStackTrace();
}
photoUri = Uri.fromFile(file);
Intent galleryIntent= new Intent(Intent.ACTION_GET_CONTENT);
galleryIntent.setType("image/*");
galleryIntent.putExtra("crop", "true");
galleryIntent.putExtra("aspectX", 2);
galleryIntent.putExtra("aspectY", 2);
galleryIntent.putExtra("outputX", 1300);
galleryIntent.putExtra("outputY", 1300);
galleryIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
startActivityForResult(galleryIntent, ACTIVITY_SELECT_IMAGE);
}
然后我保存了我的photoUri,以确保在返回时可用:
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
if (photoUri != null)
outState.putString("uri", photoUri.toString());
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
if (savedInstanceState.containsKey("uri"))
photoUri = Uri.parse(savedInstanceState.getString("uri"));
}
接着在onActivityResult中,我只需要通过photoUri打开一个InputStream,因为galleryIntent已经创建了所裁剪图像的文件。
现在,当我这样做时,意图中指定的photoUri文件永远不会被创建。是否有一种新的方法来实现这个功能?