title: How to securely load an image from camera and display it in full size on Android?
body: <p>For security, I was advised to avoid using getExternalFilesDir(Environment.DIRECTORY_PICTURES) for storing files and creating insecure temporary files with File.createTempFile.</p>
  <p>How can we rewrite this in a secure way?</p>
  <pre class="lang-java prettyprint-override"><code>clTakeBottomSheetCamera.setOnClickListener(v -&gt; {
      Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  
      if (intent.resolveActivity(getPackageManager()) != null) {
          try {
              profilePhotoFile = createPhotoFile(tag); // FIXME &lt;--
  
              Uri photoURI = FileProvider.getUriForFile(context, &quot;com.test.test&quot; + &quot;.provider&quot;, profilePhotoFile);
              intent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
  
              startActivityForResult(intent, REQUEST_CODE_CAPTURE_PASSPORT_IMAGE);
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  });
  </code></pre>
  <pre class="lang-java prettyprint-override"><code> private File createPhotoFile(String tag) throws IOException {
          String timeStamp = new SimpleDateFormat(&quot;yyyyMMdd_HHmmss&quot;, Locale.getDefault()).format(new Date());
          String imageFileName = custPhoneNumber + &quot;_&quot; + timeStamp + &quot;_&quot;;
          File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES); // FIXME: Insecure data storage
          File imgFile = File.createTempFile(imageFileName, &quot;.jpg&quot;, storageDir); // FIXME: Insecure temporary file creation
  
          profilePhotoPath = imgFile.getAbsolutePath();
          return imgFile;
      }
  </code></pre>
  <pre class="lang-java prettyprint-override"><code>@Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      if (requestCode == REQUEST_CODE_CAPTURE_PASSPORT_IMAGE &amp;&amp; resultCode == RESULT_OK) {
          // Display the captured image in an ImageView with Glide
          Glide.with(activity).load(profilePhotoPath).into(ivCustomerPhotoActivation);
      }
  }
  </code></pre>