'How to save ImageView from API to internal storage?

I'm trying to save the image from API and is always going to catch.

public void saveSkin() {
    ivSkinSaver.buildDrawingCache();
    Bitmap bm = ivSkinSaver.getDrawingCache();

    OutputStream Out = null;
    Uri outputFileUri;
    try {
        File mediaFile;
        File mediaStorageDir = new File(Environment.getExternalStorageDirectory()
                + "/Android/data/"
                + getApplicationContext().getPackageName()
                + "/Files");
        String timeStamp = new SimpleDateFormat("ddMMyyyy_HHmm").format(new Date());
        String mImageName = "MI_" + timeStamp + ".jpg";
        mediaFile = new File(mediaStorageDir.getPath() + File.separator + mImageName);
        Out = new FileOutputStream(mediaFile);
        Toast.makeText(getBaseContext(),"file saved",Toast.LENGTH_SHORT).show();

    } catch (Exception e) {
        Toast.makeText(this, "Error occured. Please try again later.",
                Toast.LENGTH_SHORT).show();
    }

    try {
        bm.compress(Bitmap.CompressFormat.PNG, 100, Out);
        Out.flush();
        Out.close();
    } catch (Exception e) {
    }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source