Storage Write on Emulator Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Storage Write on Emulator without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I am developing and android application with emulator of Android Studio 3.6. I am using a virtual device of Nexus 7 with andoird 10.

I have given permission on the manifest file and I have asked for the user to give permission for read write to the external storage.

Although permissions are ok I can not create a folder on the external storage. I attempt to write form a background proccess.

This is the excerpt og manifest file

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

This is the excerpt of my Main Activity where I ask the the user to give permission and call the background proccess: UnitDataUpdater

public class MainActivity extends AppCompatActivity {
    public static final String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";
    public static final int MY_PERMISSIONS_REQUEST_EXTERNAL_STORAGE = 1;
    // public static String SERVER_API_URL =  "";
    // public static LinearLayout examList;
    public JSONArray uiData;
    ListView examsList;

    protected void onCreate(Bundle savedInstanceState) {
        String url = "";
        String result = "";
        examsList = (ListView) findViewById(;
        UnitDataUpdater process = new UnitDataUpdater(this);
        try {
            result = process.execute(url).get();

        } catch (ExecutionException e) {
        } catch (InterruptedException e) {

    public void checkPermissions() {

        if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
                != PackageManager.PERMISSION_GRANTED
                ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)
                        != PackageManager.PERMISSION_GRANTED) {
                    new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE},

    public void onRequestPermissionsResult(int requestCode,
                                           @NonNull String[] permissions,
                                           @NonNull int[] grantResults) {


            // Checking whether user granted the permission or not.
            if (grantResults.length > 0
                    && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

                // Showing the toast message
                        "Write Permission Granted",
            } else {
                        "Write Permission Denied",


And this is the background process where I try to write to the external storage. The method getAppDi is where I am trying to create a new folder. This folder is never created so the rest of the class throws errors.

A strange thing is that at the emulator I don’t see the Document folder. I have try the same thing on Downloads folder but still the same.

public class UnitDataUpdater extends AsyncTask<String, Void, String> {
    //  private static String REMOTE_URL = "";
    private String data = "";
    public static final String REQUEST_METHOD = "GET";
    public static final int READ_TIMEOUT = 15000;
    public static final int CONNECTION_TIMEOUT = 15000;
    private String filePrefix = "i";
    private MainActivity mainActivity;

    public UnitDataUpdater(Activity mainActivity) {
        this.mainActivity = (MainActivity) mainActivity;


    private String getAppDir() {
        String externalStoragePublicDirectory = Environment

        String appDirPath = externalStoragePublicDirectory + "/XXXXUnitData";
        File appDir = new File(appDirPath);
        if (!appDir.exists()) {
            if (!appDir.mkdir()) {
                try {
                    throw new Exception("Storage Error");
                } catch (Exception e) {
                    return null;
        return appDir.getAbsolutePath();

Any help is appreciated


On Android Q external storage is not readable and writable. Use getExternalFilesDir(null) instead. You do not need any read write permission then in manifest or at runtime.

We are here to answer your question about Storage Write on Emulator - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji