3

I am having issues with the camera intent. I am testing my app on real devices - on a Sony Xperia M4 Aqua and ST23 Miro. I managed to get the app working ok on the M4 Aqua, but now I have an issue on the ST23. Every time I capture an Image it is being sent to both the extra output, and the phone's default image folder. I used to have the issue on the M4 and not the ST23, but now it's the other way around, and I cant seem to find the solution.

The camera intent:

public void callCamera()
{
    picUri = null;
    imageFile = null;
    File dir = new File(absolutePath + appPath + imagePath);
    if (dir.exists())
    {
        imageFile = new File(dir + "/" + imageName + imageFormat);
        if (imageFile.exists()) {
            boolean deleted = imageFile.delete();
            if (deleted) {
                Log.d("Image deleted", "Image has been deleted, because it already existed!");
            }
        }
    }else{
        boolean madeDirs = dir.mkdirs();
        if (madeDirs){
            Log.i("madeDirs", "Dirs were created");
            imageFile = new File(dir + "/" + imageName + imageFormat);
        }else{
            Log.i("mkdirsFail", "Could not make dirs");
        }
    }
    if (imageFile != null) {
        try {
            Uri uri = Uri.fromFile(imageFile);
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            intent.putExtra("return-data", false);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
            startActivityForResult(intent, REQUEST_IMAGE_CAPTURE);
        } catch (ActivityNotFoundException e) {
            Toast.makeText(this, getResources().getString(R.string.toast_add_part_no_camera),
                    Toast.LENGTH_SHORT).show();
        }
    }
}

OnActivityResult()

if (resultCode != RESULT_CANCELED) {
        if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
            picUri = Uri.fromFile(imageFile);
            if (picUri != null)
                performCrop(); // This is my crop function. Problem is not here.
      }//else clause
}

As I said, this works fine on my M4 Aqua (6.0 MM), but not on the ST23(4.0.4 ICS). I want to fix this, because i don't want to end up flooding the phone with unnecessary pictures in the gallery. Any ideas how to fix this?

  • `performCrop(); // This is my crop function. Problem is not here.`. Then remove the crop call to see if it indeed does not cause it. – greenapps Nov 24 '16 at 11:23
  • `if (imageFile.exists())`. Why would it exist? – greenapps Nov 24 '16 at 11:26
  • I believe following SO question has a lot of suggestions how to deal with your problem http://stackoverflow.com/questions/6390163/deleting-a-gallery-image-after-camera-intent-photo-taken?rq=1 – shtolik Nov 24 '16 at 11:47
  • Greenapps, I already tried removing crop, that's why I commented it is not the problem. The other question. Why would it exist. It's because a temporary file I create, and delete after it is done doing it's job. I am checking if the directory already exists, I am checking if the file is also present. – Теодор Митев Nov 24 '16 at 13:00
  • Shtolik, Thanks, I'll check it out, and tell you if I make any progress. – Теодор Митев Nov 24 '16 at 13:04

0 Answers0