First add permission to AndroidManifest.xml
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
Then write in the Java file as shown below.
String extr = Environment.getExternalStorageDirectory().toString(); File mFolder = new File(extr + "/MyApp"); if (!mFolder.exists()) { mFolder.mkdir(); } String strF = mFolder.getAbsolutePath(); File mSubFolder = new File(strF + "/MyApp-SubFolder"); if (!mSubFolder.exists()) { mSubFolder.mkdir(); } String s = "myfile.png"; f = new File(mSubFolder.getAbsolutePath(),s);
UPDATED
String strMyImagePath = f.getAbsolutePath(); FileOutputStream fos = null; try { fos = new FileOutputStream(f); bitmap.compress(Bitmap.CompressFormat.PNG,70, fos); fos.flush(); fos.close(); // MediaStore.Images.Media.insertImage(getContentResolver(), b, "Screen", "screen"); }catch (FileNotFoundException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); }
source share