0

the camera app that i'm writing has the permissions WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE both.

i use the getExternalStorageDirectory() method to write files to main directory of SD Card. I'm not running it on emulator. My device is Xperia Z3C and has Android 6.0.1.

when i have the path that getExternalStorageDirectory()'s given is "/storage/emulated/0/".

Then the files are saved on internal storage main directory.

 private static File getOutputMediaFile(int type){



        File mediaStorageDir = new File(Environment.getExternalStorageDirectory(), "Flash");
        Log.d("adasd", mediaStorageDir.getAbsolutePath());



        if (! mediaStorageDir.exists()){
            if (! mediaStorageDir.mkdirs()){
                Log.d("MyCameraApp", "failed to create directory");
                return null;
            }
        }


        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
        File mediaFile;
        if (type == MEDIA_TYPE_IMAGE){
            mediaFile = new File(mediaStorageDir.getPath() + File.separator +
                    "IMG_"+ timeStamp + ".jpg");
        } else if(type == MEDIA_TYPE_VIDEO) {
            mediaFile = new File(mediaStorageDir.getPath() + File.separator +
                    "VID_"+ timeStamp + ".mp4");
        } else {
            return null;
        }

        return mediaFile;
    }
Yasin Kaçmaz
  • 6,573
  • 5
  • 40
  • 58
Gogo-the-Cat
  • 57
  • 1
  • 11
  • Are you checking runtime permissions like in the link : [android-6-0-marshmallow-cannot-write-to-sd-card](http://stackoverflow.com/questions/33139754/android-6-0-marshmallow-cannot-write-to-sd-card) and read [guides/permissions](https://developers.google.com/android/guides/permissions) – Yasin Kaçmaz Jul 18 '16 at 18:12
  • Yes. When it has installed first time, asks for all permissions that i've been declareted and gives the all. – Gogo-the-Cat Jul 18 '16 at 18:18
  • "i use the getExternalStorageDirectory() method to write files to main directory of SD Card" -- [external storage](https://commonsware.com/blog/2014/04/08/storage-situation-external-storage.html) is not [removable storage](https://commonsware.com/blog/2014/04/09/storage-situation-removable-storage.html) on most Android devices. "Then the files are saved on internal storage main directory." -- no, they are not stored on [internal storage](https://commonsware.com/blog/2014/04/07/storage-situation-internal-storage.html), at least in the way the Android SDK uses the term. – CommonsWare Jul 18 '16 at 18:19
  • @CommonsWare i have already read it before asked here. but why i find them in the internal storage when i explore with one file explorer? – Gogo-the-Cat Jul 18 '16 at 18:25
  • "why i find them in the internal storage when i explore with one file explorer?" -- this is covered in [the external storage blog post that I linked to](https://commonsware.com/blog/2014/04/08/storage-situation-external-storage.html). The terms that Google uses for ordinary users are different than the terms that Google uses in the Android SDK for app developers. – CommonsWare Jul 18 '16 at 18:40

0 Answers0