且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从外部SD卡存储文件访问

更新时间:2022-05-03 01:38:28

当然可以,但你要知道,如果你正在部署的奇巧操作系统和上面的应用程序的一个重要信息。你不能在SD卡/内部存储的任何位置不再写,因为它是做过的事情。公共目录仍然可以写成(下载,图片,视频等),但仅此而已。您可以写信给私人存储您的应用程序和您的应用程序只能从它读,但你将无法查看该位置或文件,如果你浏览SD卡中的内容。唯一的例外是如果你的手机扎根。

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

写作实例APP的私有存储:

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();
        }