title: can not use MediaStore.Images.Media.insertImage
body: <p>I have a project up and running on the store, and suddenly clients start to complain about not able to capture images using my app although I did not make any changes in this part I just update android and make a new build for issue does not related to capture image </p>
  
  <p>This is my code</p>
  
  <pre><code>@Override
          public void saveImage(PictureTransaction xact, Bitmap bitmap) {
              String path = MediaStore.Images.Media.insertImage(getActivity().getContentResolver(), bitmap, getPhotoFilename(), null);
  
              if(path == null) {
                  final Activity activity = getActivity();
  
                  activity.runOnUiThread(new Runnable() {
                      @Override
                      public void run() {
                          Toast.makeText(activity, getString(R.string.photo_save_error_toast), Toast.LENGTH_SHORT).show();
                          mTakePictureBtn.setEnabled(true);
                          mProgressDialog.dismiss();
                      }
                  });
              } else {
                  Uri contentUri = Uri.parse(path);
                  final Image image = getImageFromContentUri(contentUri);
  
                  // run the media scanner service
                  // MediaScannerConnection.scanFile(getActivity(), new String[]{path}, new String[]{"image/jpeg"}, null);
                  getActivity().sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, contentUri));
  
                  // the current method is an async. call.
                  // so make changes to the UI on the main thread.
                  getActivity().runOnUiThread(new Runnable() {
                      @Override
                      public void run() {
                          ((ImagePickerActivity) getActivity()).addImage(image);
                          mTakePictureBtn.setEnabled(true);
                          mProgressDialog.dismiss();
                      }
                  });
              }
          }
  </code></pre>
  
  <p>the error that happen in the background is as following </p>
  
  <pre><code>Failed to insert image
      java.lang.SecurityException: Permission Denial: writing com.android.providers.media.MediaProvider uri content://media/external/images/media from pid=5494, uid=10570 requires android.permission.WRITE_EXTERNAL_STORAGE, or grantUriPermission()
          at android.os.Parcel.readException(Parcel.java:1693)
          at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:183)
          at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
          at android.content.ContentProviderProxy.insert(ContentProviderNative.java:476)
          at android.content.ContentResolver.insert(ContentResolver.java:1280)
          at android.provider.MediaStore$Images$Media.insertImage(MediaStore.java:1025)
          at nl.changer.polypicker.CwacCameraFragment$DemoCameraHost.saveImage(CwacCameraFragment.java:172)
          at nl.changer.polypicker.camera.ImageCleanupTask.run(ImageCleanupTask.java:136)
  </code></pre>
  
  <p>of-course I have requested the <strong>READ_EXTERNAL_STORAGE</strong>, <strong>WRITE_EXTERNAL_STORAGE</strong>, <strong>CAMERA</strong>  in my app in manifest and also in runtime permission and user accept in the dialog, but still give that error </p>
  
  <p>can anyone help please ?</p>
  
  <p><strong>EDIT</strong></p>
  
  <pre><code>if (PermissionManager.getInstance().hasSelfPermissions(getActivity(), PermissionManager.getInstance().getCameraAndStoragePermissions()) == false) {
  
              mImageAndVideoParentLayout.setVisibility(View.GONE);
              PermissionManager.getInstance().checkForCameraAndStoragePermissions2((Fragment) this, PermissionManager.CAMERA_STORAGE_PERMISSIONS);
          } else {
  
              mImageAndVideoParentLayout.setVisibility(View.VISIBLE);
          }
  ------------------------
  public boolean hasSelfPermissions(Context context, String... permissions) {
          for (String permission : permissions) {
              if (!hasSelfPermission(context, permission)) {
                  return false;
              }
          }
          return true;
      }
  -----------------------
  public String[] getCameraAndStoragePermissions() {
          return mCameraAndStoragePermissions;
      }
  -------------------------------
  private String [] mCameraAndStoragePermissions = {
  
              Manifest.permission.READ_EXTERNAL_STORAGE,
              Manifest.permission.WRITE_EXTERNAL_STORAGE,
              Manifest.permission.CAMERA
      };
  
  ---------------------------
  public void checkForCameraAndStoragePermissions2(Fragment fragment, int requestCode) {
  
          if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.M) {
  
              fragment.requestPermissions(mCameraAndStoragePermissions, requestCode);
  
          } else {
              Log.i("AMIRA", "Below M, permissions not via code");
          }
      }
  --------------------------
  @Override
      public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
  
          Log.i("AMIRA", "PostAdFragment : onRequestPermissionsResult " + requestCode);
  
          if (requestCode == PermissionManager.LOCATION_PERMISSIONS) {
              initalizeMap();
          } else if (requestCode == PermissionManager.CAMERA_STORAGE_PERMISSIONS) {
              mImageAndVideoParentLayout.setVisibility(View.VISIBLE);
          }
      }
  </code></pre>