Is it possible to create a new folder for images (to be taken through my app) to be stored in, on the android phone? (Or SD Card as far as I'm concerned). I could name it what I like [Maybe the name of my app so the files are easily found] and then the images taken by launching the camera through my app will be stored there. I'm thinking it might have something to do with Uri's. (Just a guess.)
Asked
Active
Viewed 230 times
3 Answers
4
use this code
String root = Environment.getExternalStorageDirectory().toString();
File myDir = new File(root + "/saved_images");
myDir.mkdirs();
Random generator = new Random();
int n = 10000;
n = generator.nextInt(n);
String fname = "Image-"+ n +".jpg";
File 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();
}
and add this in manifest
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
check this link Android saving file to external storage

Community
- 1
- 1

RajaReddy PolamReddy
- 22,428
- 19
- 115
- 166
1
Just use File operation for that..
File imageDirectory = new File("/sdcard/Images/"); // Path for location where you want to make directory, Internal or External storage
// have the object build the directory structure, if needed.
imageDirectory.mkdirs();
And in Application's manifest file put permission..
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>

user370305
- 108,599
- 23
- 164
- 151
1
Why not?
String path = Environment.getExternalStorageDirectory().getAbsoluteFile() + "/YourAppRootDir";
File dir = new File(path);
dir.mkdirs();

neevek
- 11,760
- 8
- 55
- 73