title: Trying to save logcat to file in Android 11
body: <p>Im trying to save the content of logcat to a file, but it fails in Android 11. This is what I have:</p>
  <pre><code>private static final String APP_DIRECTORY = Environment.getExternalStorageDirectory() + &quot;/MYAPPFOLDER&quot;;
  private static final String LOGS_FOLDER = &quot;/logs&quot;;
  private static final String FLAVOR_FOLDER = &quot;/&quot; + BuildConfig.FLAVOR;
  
  private static final int MAX_HOURS_IN_STORAGE = 360;
  
  private static final int MAX_MB_IN_STORAGE = 100;
  
  private static final int LOG_FILES_TO_SEND = 4;
  
  private static Process process;
  
  @Inject
  public LogRegisterImpl() {
  }
  
  @Override
  public void initLogRegister() throws ExternalMediaNotWritableException {
  
      checkExternalStorageWritable();
  
      if (process == null) {
  
          File appDirectory = new File(APP_DIRECTORY);
          File logDirectory = new File(appDirectory + LOGS_FOLDER);
          File flavorDirectory = new File(logDirectory + FLAVOR_FOLDER);
          // create app folder
          if (!appDirectory.exists()) {
              appDirectory.mkdirs();
          }
          // create log folder
          if (!logDirectory.exists()) {
              logDirectory.mkdirs();
          }
  
          // create flavor folder
          if (!flavorDirectory.exists()) {
              flavorDirectory.mkdirs();
          }
          ArrayList fileList = getAllFilesInDir(flavorDirectory);
          for (Object f : fileList) {
              deleteIfOlder((File) f, System.currentTimeMillis());
          }
  
          File logFile = new File(flavorDirectory, &quot;log_&quot; + DateUtils.getFileDate(new Date()) + &quot;_&quot; + BuildConfig.VERSION_NAME + &quot;_&quot; + BuildConfig.FLAVOR);
  
          // clear the previous logcat and then write the new one to the file
          try {
              Runtime.getRuntime().exec(&quot;logcat -c&quot;);
              process = Runtime.getRuntime().exec(&quot;logcat -v time -r &quot; + 1024 * MAX_MB_IN_STORAGE + &quot; -f &quot; + logFile + &quot; &quot; + BuildConfig.APPLICATION_ID );
          } catch (IOException e) {
              e.printStackTrace();
          }
  
      }
  }
  </code></pre>
  <p>My file_paths.xml:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;paths&gt;
  &lt;external-files-path name=&quot;my_files&quot; path=&quot;/&quot; /&gt;
  &lt;external-path name=&quot;logs&quot; path=&quot;MYAPPFOLDER&quot; /&gt;
  &lt;/paths&gt;
  </code></pre>
  <p>And file provider:</p>
  <pre><code>&lt;provider
              android:name=&quot;androidx.core.content.FileProvider&quot;
              android:authorities=&quot;${applicationId}.provider&quot;
              android:exported=&quot;false&quot;
              android:grantUriPermissions=&quot;true&quot;&gt;
          &lt;meta-data
                  android:name=&quot;android.support.FILE_PROVIDER_PATHS&quot;
                  android:resource=&quot;@xml/file_paths&quot;/&gt;
      &lt;/provider&gt;
  </code></pre>
  <p>I have debugged, and the logFile objet is not null, but the process is not writting anything in the file, and the file is not created.</p>
  <p>I am using an emulator with API 30.</p>