Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is there a difference between /mnt/sdcard and /sdcard?

I'm trying to save a bitmap into the Pictures directory. Here's the code

            File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);

            File file = new File(path, "test1.PNG");
            try { 
                   path.mkdirs();
                   OutputStream out = new FileOutputStream(file);
                   mBitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
                   out.flush();
                   out.close();

            } catch (Exception e) {
                   e.printStackTrace();
                   Log.w("ExternalStorage", "Error writing " + file, e);
            }

But the execution got stuck at OutputStream out = new FileOutputStream(file); I used the debugger and the full path returns mnt/sdcard/Pictures/test1.PNG, is mnt/ the culprit why I couldn't get past OutputStream out = new FileOutputStream(file);? Because I can only see sdcard/ in my file directory.

thanks!

like image 791
user1694345 Avatar asked Oct 07 '22 13:10

user1694345


2 Answers

/sdcard is a softlink to /mnt/sdcard... and /sdcard is read only in file system so better use /mnt/sdcard/..

like image 197
Charan Pai Avatar answered Oct 10 '22 03:10

Charan Pai


You can get and access the sdcard directory using this Environment.getExternalStorageDirectory() as the mnt/sdcard or sdcard/ its an device dependent directory that how OS was access and use the external directory no need to worry for different device and different directory was return by this method.

EDIT

For accessing external storage need permission and define in androidmanifest.xml file as user permission

WRITE_EXTERNAL_STORAGE
like image 29
Pratik Avatar answered Oct 10 '22 04:10

Pratik