Write this line in onCreate() method, This line of code is used for checking Sd card is available or not.
And this method is used for save your bitmap file in external and internal storage.
- Boolean isSDPresent = android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
And this method is used for save your bitmap file in external and internal storage.
- private String SaveImage_Sta(Bitmap finalBitmap, String name) {if(isSDPresent) {Log.i("isSDPresent yes", " path is==> " +isSDPresent );String root = Environment.getExternalStorageDirectory().toString() + "/profile";File myDir = new File(root);myDir.mkdirs();Random generator = new Random();int n = 10000;n = generator.nextInt(n);String fname = name + ".jpg";file = new File(myDir, fname);if (file.exists())file.delete();try {FileOutputStream out = new FileOutputStream(file);finalBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);out.flush();out.close();} catch (Exception e) {e.printStackTrace();}} else {Log.i("isSDPresent no ", " path is==> false ");ContextWrapper cw = new ContextWrapper(getApplicationContext());// path to /data/data/yourapp/app_data/imageDirFile directory = cw.getDir("imageDir", Context.MODE_PRIVATE);// Create imageDirfile =new File(directory,"profile.jpg");if (file.exists())file.delete();try {FileOutputStream fos = new FileOutputStream(file);finalBitmap.compress(Bitmap.CompressFormat.JPEG, 90, fos);fos.flush();fos.close();} catch (Exception e) {e.printStackTrace();}}return file.toString();}