diff --git a/app/src/main/java/com/donkingliang/imageselectdemo/MainActivity.java b/app/src/main/java/com/donkingliang/imageselectdemo/MainActivity.java index 498be7a..7e516af 100644 --- a/app/src/main/java/com/donkingliang/imageselectdemo/MainActivity.java +++ b/app/src/main/java/com/donkingliang/imageselectdemo/MainActivity.java @@ -10,7 +10,6 @@ import com.donkingliang.imageselectdemo.adapter.ImageAdapter; import com.donkingliang.imageselector.utils.ImageSelector; -import com.donkingliang.imageselector.utils.ImageSelectorUtils; import java.util.ArrayList; @@ -42,6 +41,8 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_CODE && data != null) { ArrayList images = data.getStringArrayListExtra(ImageSelector.SELECT_RESULT); + boolean isCameraImage = data.getBooleanExtra(ImageSelector.IS_CAMERA_IMAGE, false); +// Log.d("ImageSelector", "是否是拍照图片:" + isCameraImage); mAdapter.refresh(images); } } diff --git a/imageselector/src/main/java/com/donkingliang/imageselector/ClipImageActivity.java b/imageselector/src/main/java/com/donkingliang/imageselector/ClipImageActivity.java index b422925..bb905f7 100644 --- a/imageselector/src/main/java/com/donkingliang/imageselector/ClipImageActivity.java +++ b/imageselector/src/main/java/com/donkingliang/imageselector/ClipImageActivity.java @@ -27,6 +27,7 @@ public class ClipImageActivity extends Activity { private FrameLayout btnBack; private ClipImageView imageView; private int mRequestCode; + private boolean isCameraImage; @Override protected void onCreate(Bundle savedInstanceState) { @@ -84,6 +85,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (data != null && requestCode == mRequestCode) { ArrayList images = data.getStringArrayListExtra(ImageSelector.SELECT_RESULT); + isCameraImage = data.getBooleanExtra(ImageSelector.IS_CAMERA_IMAGE, false); Bitmap bitmap = ImageUtil.decodeSampledBitmapFromFile(images.get(0), 720, 1080); if (bitmap != null) { imageView.setBitmapData(bitmap); @@ -108,6 +110,7 @@ private void confirm(Bitmap bitmap) { selectImages.add(imagePath); Intent intent = new Intent(); intent.putStringArrayListExtra(ImageSelector.SELECT_RESULT, selectImages); + intent.putExtra(ImageSelector.IS_CAMERA_IMAGE,isCameraImage); setResult(RESULT_OK, intent); } finish(); diff --git a/imageselector/src/main/java/com/donkingliang/imageselector/ImageSelectorActivity.java b/imageselector/src/main/java/com/donkingliang/imageselector/ImageSelectorActivity.java index f29ceb2..91feafa 100644 --- a/imageselector/src/main/java/com/donkingliang/imageselector/ImageSelectorActivity.java +++ b/imageselector/src/main/java/com/donkingliang/imageselector/ImageSelectorActivity.java @@ -465,13 +465,14 @@ private void confirm() { } //点击确定,把选中的图片通过Intent传给上一个Activity。 - setResult(images); + setResult(images,false); finish(); } - private void setResult(ArrayList images) { + private void setResult(ArrayList images,boolean isCameraImage) { Intent intent = new Intent(); intent.putStringArrayListExtra(ImageSelector.SELECT_RESULT, images); + intent.putExtra(ImageSelector.IS_CAMERA_IMAGE,isCameraImage); setResult(RESULT_OK, intent); } @@ -515,7 +516,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(new File(mPhotoPath)))); ArrayList images = new ArrayList<>(); images.add(mPhotoPath); - setResult(images); + setResult(images,true); finish(); } } diff --git a/imageselector/src/main/java/com/donkingliang/imageselector/utils/ImageSelector.java b/imageselector/src/main/java/com/donkingliang/imageselector/utils/ImageSelector.java index 4ade7be..f908539 100644 --- a/imageselector/src/main/java/com/donkingliang/imageselector/utils/ImageSelector.java +++ b/imageselector/src/main/java/com/donkingliang/imageselector/utils/ImageSelector.java @@ -15,9 +15,18 @@ */ public class ImageSelector { - //图片选择的结果 + /** + * 图片选择的结果 + */ public static final String SELECT_RESULT = "select_result"; + /** + * 是否是来自于相机拍照的图片, + * 只有本次调用相机拍出来的照片,返回时才为true。 + * 当为true时,图片返回当结果有且只有一张图片。 + */ + public static final String IS_CAMERA_IMAGE = "is_camera_image"; + //最大的图片选择数 public static final String MAX_SELECT_COUNT = "max_select_count"; //是否单选