-4

how to create folder in internal storage in android studio and works in all android versions till android Q.

enter image description here

Meet Bhavsar
  • 442
  • 6
  • 12

1 Answers1

-1

AndroidManifest.xml

add Permission in manifest file

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

add request legacy external storage for application

<application
            android:requestLegacyExternalStorage="true">
</application>

MainActivity.this

add this code MainActivity.this file

File f = new File(Environment.getExternalStorageDirectory(), "My folder");
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            try {
               Files.createDirectory(Paths.get(f.getAbsolutePath()));
            } catch (IOException e) {
                e.printStackTrace();
                Toast.makeText(getApplicationContext(), e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
            }
        } else {
            f.mkdir();
            f.mkdirs();
            Toast.makeText(getApplicationContext(), f.getPath(), Toast.LENGTH_LONG).show();
        }
Meet Bhavsar
  • 442
  • 6
  • 12