'Android sdk, Apart from saving image in sd card, are there any places i can save the photo to?
I have read alot of references from the web about android storage for images. Most of them were saying Images are stored insided sd card same as photos that was taken with camera.
Does android allow us to store them in local memory in the android phone rather than sd cards?
Solution 1:[1]
To open/create a file in the internal storage, use openFileOutput(String name, int mode)
http://developer.android.com/reference/android/content/Context.html#openFileOutput(java.lang.String, int)
Solution 2:[2]
I use getCacheDir() as described in HERE under Saving cache files.
Solution 3:[3]
yeah you can store the images in cache storage , it will be private no one can see the image except from your application package.
public static String saveToCacheMemory(Activity activity, Bitmap
bitmapImage){
SimpleDateFormat mDateFormat = new SimpleDateFormat("yyyyMMddHHmmss", Locale.US);
ContextWrapper cw = new ContextWrapper(activity);
File directory = cw.getDir("imageDir", Context.MODE_PRIVATE);
// Create imageDir
File mypath=new File(directory,mDateFormat.format(new Date()) + StaticVariables.imageFormat);
Log.d(TAG, "directory: " + directory);
FileOutputStream fos = null;
try {
fos = new FileOutputStream(mypath);
// Use the compress method on the BitMap object to write image to the OutputStream
bitmapImage.compress(Bitmap.CompressFormat.PNG, 100, fos);
Log.d(TAG, "bit exception: Success" );
} catch (Exception e) {
Log.d(TAG, "bit exception: " + e.getMessage());
e.printStackTrace();
} finally {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
Log.d(TAG, "io exce: " + e.getMessage());
}
}
Log.d(TAG, "absolute path " + directory.getAbsolutePath());
return mypath.getAbsolutePath();
}
if you have more questions you can check my blog post
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Squonk |
| Solution 2 | sgarman |
| Solution 3 | General Grievance |
