title: File.listFiles() is returning null in android 11
body: <p>I was  creating an application to test whether <code>File.listFiles()</code> method is working or not. To check this I made an application and I used it there but this returning null in place of an array.
  This is my full code please help and I have granted all permissions for android 11</p>
  <p><strong>MainActivity.java</strong></p>
  <pre><code>package com.rajkumarcreations.file;
  
  import androidx.annotation.Nullable;
  import androidx.appcompat.app.AppCompatActivity;
  import androidx.core.app.ActivityCompat;
  import androidx.core.content.ContextCompat;
  
  import android.content.Intent;
  import android.content.pm.PackageManager;
  import android.net.Uri;
  import android.os.Build;
  import android.os.Bundle;
  import android.os.Environment;
  import android.provider.Settings;
  import android.widget.TextView;
  import android.widget.Toast;
  
  import org.w3c.dom.Text;
  
  import java.io.File;
  
  import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
  import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
  import static android.os.Build.VERSION.SDK_INT;
  
  public class MainActivity extends AppCompatActivity {
  TextView tv;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          tv = (TextView) findViewById(R.id.btn);
          if(!checkPermission()){
              requestPermission();
          }else{
              File file = new File(Environment.getExternalStorageDirectory()+&quot;/Download/&quot;);
              File[] allfiles = null;
              allfiles = file.listFiles();
              if(file.exists()){
                  tv.setText(&quot;Exist&quot;);
              }
              if(allfiles!=null){
                  Toast.makeText(this, &quot;length is &quot;+allfiles.length, Toast.LENGTH_SHORT).show();
              }else{
                  Toast.makeText(this, &quot;Array is null&quot;, Toast.LENGTH_SHORT).show();
              }
          }
      }
  
      private boolean checkPermission() {
          if (SDK_INT &gt;= Build.VERSION_CODES.R) {
              return Environment.isExternalStorageManager();
          } else {
              int write = ContextCompat.checkSelfPermission(MainActivity.this, WRITE_EXTERNAL_STORAGE);
              int read = ContextCompat.checkSelfPermission(MainActivity.this, READ_EXTERNAL_STORAGE);
              return write == PackageManager.PERMISSION_GRANTED &amp;&amp; read == PackageManager.PERMISSION_GRANTED;
          }
      }
  
      private void requestPermission() {
          if (SDK_INT &gt;= Build.VERSION_CODES.R) {
              try {
                  Intent intent = new Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
                  intent.addCategory(&quot;android.intent.category.DEFAULT&quot;);
                  intent.setData(Uri.parse(String.format(&quot;package:%s&quot;,new Object[]{getApplicationContext().getPackageName()})));
                  startActivityForResult(intent, 2000);
              } catch (Exception e) {
                  Intent intent = new Intent();
                  intent.setAction(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
                  startActivityForResult(intent, 2000);
              }
          } else {
              ActivityCompat.requestPermissions(MainActivity.this, new String[]{WRITE_EXTERNAL_STORAGE,READ_EXTERNAL_STORAGE}, 333);
          }
      }
  
      @Override
      protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
          if (requestCode == 2000) {
              if (SDK_INT &gt;= Build.VERSION_CODES.R) {
                  if (Environment.isExternalStorageManager()) {
  
                      Toast.makeText(this, &quot;Allow permissions granted&quot;, Toast.LENGTH_SHORT).show();
  
                  } else {
                      Toast.makeText(this, &quot;Allow permission for storage access!&quot;, Toast.LENGTH_SHORT).show();
                  }
              }
          }
      }
  
      @Override
      public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
          super.onRequestPermissionsResult(requestCode,permissions,grantResults);
          if (requestCode==333){
              if (grantResults.length &gt; 0) {
                  boolean WRITE_EXTERNAL_STORAGE = grantResults[0] == PackageManager.PERMISSION_GRANTED;
                  boolean READ_EXTERNAL_STORAGE = grantResults[1] == PackageManager.PERMISSION_GRANTED;
                  if (READ_EXTERNAL_STORAGE &amp;&amp; WRITE_EXTERNAL_STORAGE) {
  
                      Toast.makeText(this, &quot;All permissions granted&quot;, Toast.LENGTH_SHORT).show();
  
                  } else {
                      Toast.makeText(this, &quot;Allow permission for storage access!&quot;, Toast.LENGTH_SHORT).show();
                  }
              }
          }
      }
  }
  </code></pre>
  <p><strong>Manifest File</strong></p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      package=&quot;com.rajkumarcreations.file&quot;&gt;
      &lt;uses-permission android:name=&quot;android.permission.READ_EXTERNAL_STORAGE&quot;/&gt;
      &lt;uses-permission android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot;/&gt;
      &lt;uses-permission android:name=&quot;android.permission.MANAGE_EXTERNAL_STORAGE&quot;/&gt;
  
      &lt;application
          android:allowBackup=&quot;true&quot;
          android:icon=&quot;@mipmap/ic_launcher&quot;
          android:label=&quot;@string/app_name&quot;
          android:roundIcon=&quot;@mipmap/ic_launcher_round&quot;
          android:supportsRtl=&quot;true&quot;
          android:requestLegacyExternalStorage=&quot;true&quot;
          android:theme=&quot;@style/AppTheme&quot;&gt;
          &lt;activity android:name=&quot;.MainActivity&quot;&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;
  
                  &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  <p><strong>XML File</strong></p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      tools:context=&quot;.MainActivity&quot;&gt;
  
      &lt;TextView
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:text=&quot;Hello World!&quot;
          android:id=&quot;@+id/btn&quot;
          app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
          app:layout_constraintLeft_toLeftOf=&quot;parent&quot;
          app:layout_constraintRight_toRightOf=&quot;parent&quot;
          app:layout_constraintTop_toTopOf=&quot;parent&quot; /&gt;
  
  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  </code></pre>