Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static File getDir() {
- File sdDir = getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
- return new File(sdDir, "MyPics");
- }
- public static boolean writeFile(byte[] data, String fileName, Context context) {
- File pictureFileDir = getDir();
- if (!pictureFileDir.exists() && !pictureFileDir.mkdirs()) {
- Toast.makeText(context, "CANT CREATE", Toast.LENGTH_SHORT).show();
- }
- String photoFile = fileName + ".jpg";
- String fullPath = pictureFileDir.getAbsolutePath() + File.separator + photoFile;
- File pictureFile = new File(fullPath);
- Toast.makeText(context, "FULL PATH: "+fullPath, Toast.LENGTH_SHORT).show(); // This returns "/storage/emulated/0/Pictures/MyPics/FILENAME.jpg"
- try {
- FileOutputStream fos = new FileOutputStream(pictureFile);
- fos.write(data);
- fos.close();
- } catch (Exception error) {
- Toast.makeText(context, "File "+fullPath+ "not saved", Toast.LENGTH_SHORT).show();
- return false;
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement