unable to decode stream java.io.FileNotFoundException /storage/emulated/0 open failed:ENOENT(No such file or directory

后端 未结 5 599
慢半拍i
慢半拍i 2021-01-13 22:23

hello i\'m trying to save pictures taken on my application, but when i try to access the memory to place the data, an error comes out

unable to decode stream java.io

5条回答
  •  忘掉有多难
    2021-01-13 23:10

    You need to write to external storage, make sure you added the permission:

    
        
        ...
    
    

    Checks if external storage is available for read and write:

    public boolean isExternalStorageWritable() {
        String state = Environment.getExternalStorageState();
        if (Environment.MEDIA_MOUNTED.equals(state)) {
            return true;
        }
        return false;
    }
    

    Use the root of the public directory instead of using the root of Android.

    If you want to save public files on the external storage, use the getExternalStoragePublicDirectory()

    public File getAlbumStorageDir(String albumName) {
        // Get the directory for the user's public pictures directory. 
        File file = new File(Environment.getExternalStoragePublicDirectory(
                Environment.DIRECTORY_DCIM), albumName);
        if (!file.mkdirs()) {
            Log.e(LOG_TAG, "Directory not created");
        }
        return file;
    }
    

    If you want to save files that are private to your app, use the getExternalFilesDir()

    public File getAlbumStorageDir(Context context, String albumName) {
        // Get the directory for the app's private pictures directory. 
        File file = new File(context.getExternalFilesDir(
                Environment.DIRECTORY_DCIM), albumName);
        if (!file.mkdirs()) {
            Log.e(LOG_TAG, "Directory not created");
        }
        return file;
    }
    

    More information on the link http://developer.android.com/training/basics/data-storage/files.html

提交回复
热议问题