Android 避免在应用程序中使用“照相机”或“多媒体资料”选项选择重复图像

Android 避免在应用程序中使用“照相机”或“多媒体资料”选项选择重复图像,android,image,Android,Image,我有一个添加属性的功能,允许用户使用相机或画廊选项拍摄属性的图像。我希望用户避免拍摄重复图像,以便无论何时用户尝试选择重复图像,都可以限制用户这样做。 这是我的密码 final String[] items = new String[] { "From Camera", "From Gallery" }; ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, an

我有一个添加属性的功能,允许用户使用相机或画廊选项拍摄属性的图像。我希望用户避免拍摄重复图像,以便无论何时用户尝试选择重复图像,都可以限制用户这样做。 这是我的密码

    final String[] items = new String[] { "From Camera", "From Gallery" };
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.select_dialog_item, items);
    AlertDialog.Builder builder = new AlertDialog.Builder(this);

    builder.setTitle("Select Image");
    builder.setAdapter(adapter, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int item) {
            if (item == 0) {
                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                extStorageDirectory = UtilsMethos.CreateAppFolder(AddPropertyActivity.this);
                File file = new File(extStorageDirectory, getString(R.string.app_name)+"_"+ String.valueOf(System.currentTimeMillis())+ ".png");
                mImageCaptureUri = Uri.fromFile(file);
                intent.putExtra(MediaStore.EXTRA_OUTPUT, mImageCaptureUri);
                try {
                    intent.putExtra("return-data", true);
                    startActivityForResult(intent, PICK_FROM_CAMERA);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                dialog.cancel();
            } else {


                if (Build.VERSION.SDK_INT <19){
                    Intent intent = new Intent();
                    intent.setType("image/*");
                    intent.setAction(Intent.ACTION_GET_CONTENT);
                    startActivityForResult(intent, PICK_FROM_FILE);
                } else {
                    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
                    intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
                    intent.addCategory(Intent.CATEGORY_OPENABLE);
                    intent.setType("image/*");
                    startActivityForResult(intent, GALLERY_KITKAT_INTENT_CALLED);
                }
            }
        }
    });

    final AlertDialog dialog = builder.create();
    //      dialog.setCanceledOnTouchOutside(false);
    dialog.show();
}
And in OnActivityResult() my code is 
if (requestCode == PICK_FROM_FILE) {
                    mImageCaptureUri = intent.getData();
                }else if (requestCode == GALLERY_KITKAT_INTENT_CALLED) {
                    mImageCaptureUri = intent.getData();
                    if(mImageCaptureUri == null){
                        addMultipleImage(intent);
                        return;
                    }
                    final int takeFlags = intent.getFlags()
                            & (Intent.FLAG_GRANT_READ_URI_PERMISSION
                                    | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
                    // Check for the freshest data.
                    getContentResolver().takePersistableUriPermission(mImageCaptureUri, takeFlags);
                }
                //          String selectedImagePath = UtilsMethos.getPath(mImageCaptureUri,this);
                String selectedImagePath = UtilsMethos.getPath(this, mImageCaptureUri);
                Bitmap bitmap = UtilsMethos.getBitmapFromPath(selectedImagePath);
final String[]items=新字符串[]{“来自摄影机”,“来自画廊”};
ArrayAdapter=新的ArrayAdapter(此,
android.R.layout.select_对话框_项目,项目);
AlertDialog.Builder=新建AlertDialog.Builder(此);
builder.setTitle(“选择图像”);
setAdapter(适配器,新的DialogInterface.OnClickListener(){
公共void onClick(对话框接口对话框,int项){
如果(项==0){
意向意向=新意向(MediaStore.ACTION\u IMAGE\u CAPTURE);
extStorageDirectory=utilsmethodos.CreateAppFolder(AddPropertyActivity.this);
File File=新文件(extStorageDirectory,getString(R.string.app_name)+“”+string.valueOf(System.currentTimeMillis())+”.png”);
mImageCaptureUri=Uri.fromFile(文件);
intent.putExtra(MediaStore.EXTRA_输出,mImageCaptureUri);
试一试{
intent.putExtra(“返回数据”,true);
startActivityForResult(意图,从摄像机中拾取);
}捕获(例外e){
e、 printStackTrace();
}
dialog.cancel();
}否则{

如果(Build.VERSION.SDK_INT,问题是什么?@Epodax我希望用户在选择“使用照相机或多媒体资料”选项时避免选择重复图像。如果用户使用camara,他不会选择图像,而是拍摄新图像。那么在拍摄照片时,您会如何描述重复图像?@greenapps是的,这正是我要问的r???你没有回答我的问题。请回答这个问题。