Question: I'm trying to create a folder in the internal storage of the phone but it just doesn't create it no matter what i do

Things I've tried:

* unplugging the phone from the computer
* set permissions both in manifest and programatically for API 23+
* every single variation of folder getting i could find:
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY\_DOWNLOADS)
Environment.getDataDirectory()
etc..
* searched every single article or variation of the article for similar problems
* tried both variations of mkdir() and mkdirs()
* checked phone if folder exists

This code is also tied to a button so the permission asking should already be granted the second time i press it.

```java
File sdir = new File (Environment.getExternalStorageDirectory().getpath(), "/DBTEST/");

String[] PERMISSIONS_STORAGE = {
        Manifest.permission.WRITE_EXTERNAL_STORAGE
};
ActivityCompat.requestPermissions(MainActivity.this, PERMISSIONS_STORAGE, 1);

System.out.println("DIRECTORY CREATED: " + sdir.mkdirs());
System.out.println("EXISTS: " + sdir.exists());

```

```
System.out: DIRECTORY CREATED: false
System.out: EXISTS: false

```

```xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.example.testM">

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

```

Answer: 
Try changing this line:

`File sdir = new File (Environment.getExternalStorageDirectory().getpath(), "/DBTEST/");`

to

`File sdir = new File (Environment.getExternalFilesDir(null) + "/DBTEST/");`

According to the developer docs:

> 
> getExternalStorageDirectory() -
>  This method was deprecated in API level 29.
>  To improve user privacy, direct access to shared/external storage devices is deprecated. When an app targets Build.VERSION\_CODES.Q, the path returned from this method is no longer directly accessible to apps. Apps can continue to access content stored on shared/external storage by migrating to alternatives such as Context#getExternalFilesDir(String), MediaStore, or Intent#ACTION\_OPEN\_DOCUMENT. 
> 
> 
> 

`getExternalFilesDir(null)` will return your apps storage folder at (Internal Storage)/Android/data/your.app.name/file/

If you want to access certain OS defined folders you just pass environmental constants defined here: 

<https://developer.android.com/reference/android/content/Context#getExternalFilesDir(java.lang.String)>

and here

<https://developer.android.com/reference/android/os/Environment>

under the "Fields" section.

Ex. downloads would be: `getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)`
This is a privacy restriction introduced in Android-Q. Direct access to shared/external storage devices is deprecated when an app targets API 29 and the path returned from [getExternalStorageDirectory](https://developer.android.com/reference/android/os/Environment.html#getExternalStorageDirectory()) method is no longer directly accessible to apps. Use the app-specific directory to write & read files.

*By default, apps targeting Android 10 and higher are given [scoped access into external storage](https://developer.android.com/training/data-storage/files/external-scoped), or scoped storage. Such apps can see the following types of files within an external storage device without needing to request any storage-related user permissions:*

* Files in the app-specific directory, accessed using [getExternalFilesDir()](https://developer.android.com/reference/android/content/Context#getExternalFilesDir(java.lang.String)).
* Photos, videos, and audio clips that the app created from the [media store](https://developer.android.com/training/data-storage/files/media).