title: Writing to the external storage is not working anymore on Nougat
body: <p>I wrote a little app to learn how to write and read files.
  It worked, but now I can't write files any more..</p>
  
  <p>1.I added to Manifest:</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
  &lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
  </code></pre>
  
  <p>2.In MainActivity</p>
  
  <pre><code>// permissions array:
  final String[] permissions = new String[]{Manifest.permission.ACCESS_FINE_LOCATION,
          Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE};
  // permission code for action multiple permission request:
  private static final int ALL_PERMISSIONS = 101;
  </code></pre>
  
  <p>3.OnCreate (MainActivity):</p>
  
  <pre><code>// check multiple permissions:
      ActivityCompat.requestPermissions(this, permissions, ALL_PERMISSIONS);
  </code></pre>
  
  <p>4.onRequestPermissionsResult (@override MainActivity ):</p>
  
  <pre><code>    @Override
  public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
      super.onRequestPermissionsResult(requestCode, permissions, grantResults);
      // for PERMISSION_CODE:
      switch (ALL_PERMISSIONS){
          case 101:
              // if grantResults is populated:
              if(grantResults.length &gt; 0){
                  // 1° permission check:
                  if(grantResults[0] == PackageManager.PERMISSION_GRANTED){
                      reportText.append("\n GPS permission granted");
                  }
                  else{ reportText.append("\n no GPS permissions"); }
                  // 2° permission check. NOTE: write permission is such as READ permission?
                  if(grantResults[1] == PackageManager.PERMISSION_GRANTED){
                      reportText.append("\n WRITE permission granted");
                  }
                  else{ reportText.append("\n no WRITE permissions"); }
                  if(grantResults[2] == PackageManager.PERMISSION_GRANTED){
                      reportText.append("\n READ permission granted");
                  }
                  else{reportText.append("\n no READ permissions"); }
              }
      }
  }
  </code></pre>
  
  <p>5. OnButtonClickSave():</p>
  
  <pre><code>public void onButtonSave(View view){
      // get text from EditView
      String textToSave = inputText.getText().toString();
      dir.mkdir();
      // check if folder exists:
      if (!dir.exists()){
          // if not, create it:
          dir.mkdir();
      }
      try {
          // write to file:
          FileOutputStream fos = new FileOutputStream(file, true);
          fos.write(textToSave.getBytes());
          fos.close();
          // add files to explorer (update device explorer)
          Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
          intent.setData(uri);
          sendBroadcast(intent);
          // send message to activity-layout:
          reportText.append("\n file saved" + file.toString());
      } catch (IOException e) {
          // else error
          e.printStackTrace();
          reportText.append("\n file not saved");
      }
  }
  </code></pre>
  
  <p>I setted also a TextView (called report as you can see in code) that give all permissions granted, but I can't save any file.
  (FILE NOT FOUND).</p>
  
  <p>What is wrong with this?
  (this app was working until some days ago)..</p>
  
  <p>EDIT:</p>
  
  <p>Sorry for that, I missed to give you file paths (onCreate):</p>
  
  <pre><code>        // create dir, file and Uri:
      dir = new File (Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), filepath);
      file = new File(dir, fileName);
      uri = Uri.fromFile(file);
  </code></pre>