Camera X - Android - How can I give pictures I've taken a specific tag in order to categorize them?

Viewed 43

Hey Guys,

this is my first question here, so sorry if I'm missing something out.

I just started to use Camera X for Android (Java) and I managed to save a picture to a specific file location, which I've declared. Well my problem or question is, if it's possible to give the pictures specific tags in order to categorize them.

For example:

I have two categories (#1, #2) and if I shoot a picture for the first category, I want to tag that picture with the tag #1, but it’s stored in the same folder. It should then be possible to read the pictures from the folder and then sort them by tag.

What’s your idea?

I thought it would be possible to manipulate the file-name, but I'm not sure how to do it.

Below is my current code to shoot an image (in a Fragment):

private void capturePhoto() {
        long timestamp = System.currentTimeMillis();

        ContentValues contentValues = new ContentValues();
        contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME, timestamp);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
            contentValues.put(MediaStore.Images.Media.RELATIVE_PATH, Environment.DIRECTORY_PICTURES + "/" + "Test/");
        }
        contentValues.put(MediaStore.MediaColumns.MIME_TYPE, "image/jpeg");


        imageCapture.takePicture(
                new ImageCapture.OutputFileOptions.Builder(
                getContext().getContentResolver(),
                        MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                        contentValues
                ).build(), getExecutor(),
                new ImageCapture.OnImageSavedCallback() {
                    @Override
                    public void onImageSaved(@NonNull ImageCapture.OutputFileResults outputFileResults) {
                        Toast.makeText(requireContext(), "Photo has been saved successfully.", Toast.LENGTH_SHORT).show();
                        Toast.makeText(requireContext(), Objects.requireNonNull(outputFileResults.getSavedUri()).getPath(), Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onError(@NonNull ImageCaptureException exception) {
                        Toast.makeText(requireActivity(), "Error saving photo: " + exception.getMessage(), Toast.LENGTH_SHORT).show();
                    }
                }
        );
    }
    
0 Answers
Related