遇到个这样的问题,就是吃了没马上看源码的亏,想当然的以为setDateAndType拆开来应该也能用。
拍照和从相册选择图片剪切时由于拍照的时候有路径传回,就需要判断。
懒人的懒办法就出来了,拆setDateAndType,自己还挺开心的。
接着这一块的功能就不能用了。找半天......................................................
public static Intent getCropImageIntent(Uri photoUri) {
Intent intent = null;
if (photoUri !=null) {
intent = new Intent("com.android.camera.action.CROP");
intent.setData(photoUri);
intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
}else {
intent = new Intent(Intent.ACTION_GET_CONTENT, null);
}
intent.setType("image/*");
// crop=true 设置在开启的Intent中显示的VIEW可裁剪
intent.putExtra("crop", "true");
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("outputX", 80);
intent.putExtra("outputY", 80);
intent.putExtra("return-data", true)
return intent;
}
*************************************************************************************************************************************
逐渐定位到问题所在,然后就骂街了。。
这几个set方法在源码当中是这样的:
public Intent setData(Uri data) { mData = data; mType = null; return this; }
public Intent setType(String type) { mData = null; mType = type; return this; }
public Intent setDataAndType(Uri data, String type) { mData = data; mType = type; return this; }
public static Intent getCropImageIntent(Uri photoUri) {
Intent intent = null;
if (photoUri !=null) {
intent = new Intent("com.android.camera.action.CROP");
intent.setDataAndType(photoUri, "image/*");
intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
}else {
intent = new Intent(Intent.ACTION_GET_CONTENT, null);
intent.setType("image/*");
}
// crop=true 设置在开启的Intent中显示的VIEW可裁剪
intent.putExtra("crop", "true");
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("outputX", 80);
intent.putExtra("outputY", 80);
intent.putExtra("return-data", true);
return intent;
}
留个记忆,重新做人