简体   繁体   中英

Accessing files from external SD card memory

I am very new to Android ecosystem. Can I make a definitive conclusion that any stored files in an external SD memory can be read by any apps?

Caution Although the directories provided by getExternalFilesDir() and getExternalFilesDirs() are not accessible by the MediaStore content provider, other apps with the READ_EXTERNAL_STORAGE permission can access all files on the external storage, including these. If you need to completely restrict access for your files, you should instead write your files to the internal storage. ( http://developer.android.com/guide/topics/data/data-storage.html#filesExternal )

Yes you can, BUT there is an important piece of information you need to know if you are deploying the app on KitKat OS and above. You cannot no longer write at any location in the SD card/internal storage as it was done before. The public directories can still be written in(Downloads, Pictures, Videos, etc), but that's it. You can write to private storage for your app and your app can only read from it, BUT you won't be able to view that location or the file if you were browsing the contents of the sdCard. The only exception is if your phone was rooted.

http://www.androidcentral.com/kitkat-sdcard-changes

Example of writing to app private storage:

//Write to internal app storage
            FileOutputStream internalStorage = null;

        try
        {
            internalStorage = openFileOutput("capturedImage", Context.MODE_PRIVATE);

        } 
        catch (FileNotFoundException e1)
        {
            e1.printStackTrace();
        }

        BufferedOutputStream buffer_output = new BufferedOutputStream(internalStorage);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, buffer_output);
        try
        {
            buffer_output.flush();
            buffer_output.close();
        }
        catch (IOException e)
        {

            e.printStackTrace();
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM