0

Fetching images one by one to android app then saving count of pictures on textview. Here if same image fetched again in to android app then don't want to increase the count of textview, how to handle this?

public class GetImageActivity extends Activity {

    private static final int SELECT_PICTURE = 1;

    private String selectedImagePath;
    private ImageView img;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        img = (ImageView)findViewById(R.id.ImageView01);

        ((Button) findViewById(R.id.Button01))
                .setOnClickListener(new OnClickListener() {
                    public void onClick(View arg0) {
                        Intent intent = new Intent();
                        intent.setType("image/*");
                        intent.setAction(Intent.ACTION_GET_CONTENT);
                        startActivityForResult(Intent.createChooser(intent,"Select Picture"), SELECT_PICTURE);
                    }
                });
    }

    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == RESULT_OK) {
            if (requestCode == SELECT_PICTURE) {
                Uri selectedImageUri = data.getData();
                selectedImagePath = getPath(selectedImageUri);
                System.out.println("Image Path : " + selectedImagePath);
                img.setImageURI(selectedImageUri);
            }
        }
    }

    public String getPath(Uri uri) {
        String[] projection = { MediaStore.Images.Media.DATA };
        Cursor cursor = managedQuery(uri, projection, null, null, null);
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        return cursor.getString(column_index);
    }
}
Mattia Maestrini
  • 32,270
  • 15
  • 87
  • 94
Prabha1
  • 233
  • 1
  • 4
  • 22

2 Answers2

0

you can do it by using md5 checksum if two images are identical then their checksum value will also be identical.

Sumit Jain
  • 87
  • 9
0

You must be getting a URI of the image. Maintain a HashSet of the URIs. HashSet will remove the duplicates for you.

In the textview you can just show the size of the HashSet, that will always show the unique number of images.

PS: md5 is also a solution, but TOO TOO slow for your use case. In case you have the same image coming with different URIs (same images placed at different places on the storage), you may have to go for md5 if you want to make that unique.

Aman Gautam
  • 3,549
  • 2
  • 21
  • 25
  • hi Aman, i have to get all duplicate images of device and show into gridview and my requirement is to delete manually duplicate imgs, please give me solution if any. – Mohd Saquib Dec 07 '17 at 06:47