aspose file tools*
The moose likes Android and the fly likes How to store images to SDCard and get string file path Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "How to store images to SDCard and get string file path " Watch "How to store images to SDCard and get string file path " New topic
Author

How to store images to SDCard and get string file path

Ciaran Mooney
Ranch Hand

Joined: Jan 21, 2013
Posts: 65

Hi,
I am looking to save a large amount of images
to a SQLite DB (150+).I was thinking of saving as
base64 string but am concerned about space.
So was wondering how to store images on SDCard as files and put a string filepath to DB to allow retrieval of images when a row is called.

Thanks
Ciaran

Ps this should be in android forum , does anyone no how I can redirect and post there


I love deadlines, I love the whooshing sound they make as they fly by...
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39529
    
  27
I agree that storing as files is better than in the DB. SD storage is explained here: http://developer.android.com/guide/topics/data/data-storage.html#filesExternal


Ping & DNS - updated with new look and Ping home screen widget
Ciaran Mooney
Ranch Hand

Joined: Jan 21, 2013
Posts: 65

Yep code from site great guide, works fine:

// check if ext storage is available to write
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {

canSaveToExternalSD = true;
String root = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES).toString()
+ "/saved_images";
File myDir = new File(root);
myDir.mkdirs();
String photoName = "image" + diveNum + ".jpg";
File file = new File(root + "/" + photoName);
if (file.exists()) {
file.delete();
makeToast("Photo currently exists!'");

try {
FileOutputStream out = new FileOutputStream(file);
image.compress(Bitmap.CompressFormat.JPEG, 90, out);// compress
// image fro
// output
out.flush();
out.close();

I forgot to add the WRITE_EXTERNAL_STORAGE permission in manifest which did give Ne FileNotFound exceptions as directory was never created, just something to watch out for
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to store images to SDCard and get string file path
 
Similar Threads
Image gets stored
Store an image in the sdcard
how to create sdcard and mount on the emulator
How to display Images stored on sdcard?
Capture image using android emulator