title: Android -Permission Denial: writing com.android.providers.downloads.DownloadStorageProvide
body: <p>In my application i have requirement to after selected file from gallery user can remove selected file, but i could not found any suitable solution for how to remove selected URI, if i converted it to file and deleted it, then file deleted permanently from file storage also any suggestion<br>
  <strong>UPDATE:</strong>
  i try below code also but its given exception 
  "Attempt to invoke virtual method 'android.content.ContentResolver android.content.Context.getContentResolver()' on a null object reference"</p>
  
  <pre><code> @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
      if (requestCode == MY_PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION &amp;&amp; resultCode == Activity.RESULT_OK) {
          uri = data.getData();
          //String filePath = getRealPathFromURIPath(uri, CreateInquiry.this);
          String filePath = FileUtils.getRealPath(getApplicationContext(),uri);
          File file = new File(filePath);
          remove(uri);
        AttachedFileDao dao=new AttachedFileDao();
        dao.setFileName(file.getName());
        dao.setFileUri(filePath);
  
  
          attachedFile.add(dao);
  
          fileAdpter=new AttachedFileAdpter(attachedFile,getApplicationContext());
          recyclerView.setAdapter(fileAdpter);
  
  
  
  
      }
  }
  
  public boolean remove(final Uri uri) {
      try {
          context.getContentResolver().delete(uri, null, null);
          return true;
      } catch (Throwable e) {
          e.printStackTrace();
          return false;
      }
  }
  </code></pre>
  
  <p>after getting the result in onactivity result i just want to remove remove selected file path data, so if user selected wrong file then he able to deleted the file without upload.
  <strong>update 2</strong>
  while calling calling getcontentResolver i am getting security exception like</p>
  
  <p>Caused by: java.lang.SecurityException: Permission Denial: writing com.android.providers.downloads.DownloadStorageProvider uri content://com.android.providers.downloads.documents/document/raw%3A%2Fstorage%2Femulated%2F0%2FDownload%2FCSP.pdf from pid=22959, uid=10115 requires android.permission.MANAGE_DOCUMENTS, or grantUriPermission()</p>
  
  <p>but i added all permission any solution for that.</p>