嗨,我有这个应用程序,允许用户拍摄图像和裁剪。它适用于我的手机,但不适用于我的三星 Galaxy 平板电脑。“保存图像”对话框仍然存在,不会返回到我的应用程序的 onActivityResult ...如果我取消裁剪,它确实会返回 [
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == 1337 && resultCode == -1) {
File fi = new File("/sdcard/tmp");
// get the Uri for the captured image - NEW
try {
mImageCaptureUri = Uri
.parse(android.provider.MediaStore.Images.Media
.insertImage(getContentResolver(),
fi.getAbsolutePath(), null, null));
// Log.i("",String.valueOf(thumbnail.getHeight()));
} catch (Exception ex) {
String errorMessage = "Your device doesn't support the crop action!";
Toast toast = Toast.makeText(this, errorMessage,
Toast.LENGTH_SHORT);
toast.show();
}
performCrop();
}
if (requestCode == PIC_CROP) {
try {
final TextView imgTv = (TextView) findViewById(R.id.info);
// Bundle extras = data.getExtras();
// thumbnail = extras.getParcelable("data");
Log.i("a", "test");
// NEW
final String filePath = Environment.getExternalStorageDirectory()
+ "/temporary_holder.jpg";
thumbnail = BitmapFactory.decodeFile(filePath);
ImageView image = (ImageView) findViewById(R.id.img);
image.setImageBitmap(thumbnail);
}}
private void performCrop() {
try {
// call the standard crop action intent (the user device may not
// support it)
Intent cropIntent = new Intent("com.android.camera.action.CROP");
// indicate image type and Uri
cropIntent.setDataAndType(mImageCaptureUri, "image/*");
// set crop properties
cropIntent.putExtra("crop", "true");
// indicate aspect of desired crop
cropIntent.putExtra("aspectX", 4);
cropIntent.putExtra("aspectY", 3);
// indicate output X and Y
cropIntent.putExtra("outputX", 500);
cropIntent.putExtra("outputY", 300);
// retrieve data on return
// cropIntent.putExtra("return-data", true);
File f = new File(Environment.getExternalStorageDirectory(),
"/temporary_holder.jpg");
try {
f.createNewFile();
} catch (IOException ex) {
Log.e("io", ex.getMessage());
}
uri = Uri.fromFile(f);
cropIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
startActivityForResult(cropIntent, PIC_CROP);
} // respond to users whose devices do not support the crop action
catch (ActivityNotFoundException anfe) {
// display an error message
String errorMessage = "Your device doesn't support the crop action!";
Toast toast = Toast
.makeText(this, errorMessage, Toast.LENGTH_SHORT);
toast.show();
}
}