title: How can I take a photo and save in Android Q?
body: <p>NEW EDIT:</p>
  
  <p>I'm developing an android application and want to support android Q. When my app runs in target API(&lt;= 28), everything works normally. But in android Q, when i take a photo and try to save it, something strange happens.</p>
  
  <p>When I take the first photo, I can find it in my custom photo picker.
  But I can't find the other photos taken after the first one. </p>
  
  <p>But I can find all the photos by using adb in terminal.
  Anyone has some suggestions?</p>
  
  <p>I take photo like this:</p>
  
  <pre><code>Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  mCameraFilePath = MediaDataManager.getInstance().getFilePath(MediaDataManager.IMAGE, fileName);
  // this function returns the img file path, like /storage/emulated/0/Android/data/&lt;package-name&gt;/files/Pictures/1556592144304.png
  mCameraPicUri = FileProvider.getUriForFile(getActivity(), BuildConfig.APPLICATION_ID + ".fileprovider", new File(mCameraFilePath));
  cameraIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
  cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCameraPicUri);
  startActivityForResult(cameraIntent, CAMERA_REQUEST_CODE);
  </code></pre>
  
  <p>and save photo:</p>
  
  <pre><code>try {
      File file = new File(=getExternalFilesDir(Environment.DIRECTORY_PICTURES), fileName + ".png");
      if (file.exists()) {
           file.delete();
           file.createNewFile();
      }
       InputStream inputStream = =getContentResolver().openInputStream(mCameraPicUri);
       FileOutputStream out = null;
       try {
           out = new FileOutputStream(file);
           if (inputStream != null) {
                 copy(inputStream, out);
                 inputStream.close();
           }
  
           if (out != null) {
               out.close();
           }
       } catch (FileNotFoundException e) {
           e.printStackTrace();
       } catch (IOException e) {
            e.printStackTrace();
       }
  }
  
  Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, mCameraPicUri);
  sendBroadcast(mediaScanIntent);
  </code></pre>
  
  <p>Here is the copy() method:</p>
  
  <pre><code>private static final int EOF = -1;
  private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
  private static long copy(InputStream input, OutputStream output) throws IOException {
       long count = 0;
       int n;
       byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
       while (EOF != (n = input.read(buffer))) {
           output.write(buffer, 0, n);
           count += n;
       }
       return count;
  }
  </code></pre>
  
  <p>SOLUTION:
  I should create the uri like this:</p>
  
  <pre><code>ContentValues values = new ContentValues();
  values.put(MediaStore.Images.Media.TITLE, fileName);
  values.put(MediaStore.Images.Media.MIME_TYPE, "image/png");
  mCameraPicUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
  </code></pre>