Android: save files in internal storage in a directory publicly

I am trying to save images in a directory inside the application file directory publicly. In public, I mean that I can use the intention of acting on it.

/** Saves the bitmap to app storage */
    public int SaveBitmap(Bitmap bitmap, String filename, Boolean scan){

        // Save the file
        OutputStream os = null;

        String path = context.getFilesDir() + "/MyAppName/";
        File file = new File(path);
        if(!file.isDirectory())file.mkdirs();
        path += (filename + ".png");
        try {
            os = new BufferedOutputStream(new FileOutputStream(path,true));
            //os = mContext.openFileOutput(, Context.MODE_PRIVATE);
            bitmap.compress(CompressFormat.PNG, 100, os);
            os.flush();
            os.close();
            bitmap.recycle();
        } catch (IOException e) {
            e.printStackTrace();
            return 1; //Failure
        }

        File fileR = new File(path);

        fileR.setReadable(true, false);
        // Show in Gallery
        if(scan) ShowInGallery(filename);

        return 0; // SUCCESS

    }

This piece of code does not complete the task; files are still being created in closed mode.

Using:

context.openFileOutput(filename + ".png", Context.MODE_WORLD_READABLE); 

I managed to open them publicly, but I can not save the file in a directory.

Please note that I am targeting users who do not have SD cards, so I do not use External Storage.

What can I do?

+3
source share
2 answers

, - Environment.getExternalStoragePublicDirectory (String type) , , getFilesDir. .

, getExternalStoragePublicDirectory , SD-, . .

0

Environment.getExternalStoragePublicDirectory (String type) Environment.getExternalStorageDirectory . . .

Edit:

getExternalStorageDirectory ():

. "" . / . , ( ). SD-, , .

"" , . , SD- , . SD-, .

+6

All Articles