1

I have this code which is part of picture capturing I'm making:

private File createTemporaryFile(String part, String ext) throws Exception {
    File tempDir= Environment.getExternalStorageDirectory();
    //Solution I found in another question:
    //File tempDir = super.getFilesDir();
    tempDir=new File(tempDir.getAbsolutePath()+"/.temp/");

    if(!tempDir.exists()) {
        tempDir.mkdirs();
    }
    return File.createTempFile(part, ext, tempDir);
}

It used to work well, but now for some unknown reason it gives me a "Permission Denied" exception to the createTempFile method. So I tried a solution I found here, and Whenever I capture the image in the startActivityForResult activity, it proccesses the image forever. Anyone has an idea why it stopped working out of the blue or how to fix it? Edit: I thought it might be a problem with my device, it wasn't. It's the same in another device.

Ori Zehavi
  • 11
  • 3
  • `tempDir.mkdirs();`. Check the return value and handle accordingly. I bed the directory is not created to begin with. – greenapps Apr 30 '18 at 19:37
  • @greenapps checked it now, it is created, this is not the problem. A week ago it worked perfectly, I have no idea why it suddenly stopped working. – Ori Zehavi Apr 30 '18 at 20:57

1 Answers1

0

I managed to figure it out. I only needed to add a permission manually to the files from the app itself, I only did it to the camera. Here's what I did:

//Permission to the camera and files
    if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.CAMERA) == PackageManager.PERMISSION_DENIED)
    {
        ActivityCompat.requestPermissions(this, new String[] {android.Manifest.permission.CAMERA,android.Manifest.permission.WRITE_EXTERNAL_STORAGE }, CAMERA_REQUEST_CODE);
    }
Ori Zehavi
  • 11
  • 3