0

I am new in Android. I want to store my image(which is chosen from gallery or tack picture from Camera) locally(i.e. SharedPreferences). I want to save my images till application will run in device. Once application will be removed from device then all data will be removed.

Can anyone help me?

Thanks.

anddev
  • 3,144
  • 12
  • 39
  • 70
  • You should add more details... you speak about one picked image, and then image**s**... BTW, look the android services... if you want that your application saves the images even when it's not launched. – Whiler Sep 05 '11 at 08:47

1 Answers1

0

call this function for save..

void saveImage() {

File myDir=new File("/sdcard/saved_images");
    myDir.mkdirs();

    String fname = "Image.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();
           final AlertDialog alertDialog = new AlertDialog.Builder(this).create();  
                alertDialog.setTitle("Save");  
                alertDialog.setMessage("Your drawing had been saved:)");  
                alertDialog.setButton("OK", new DialogInterface.OnClickListener() {  
                public void onClick(DialogInterface dialog, int which) { 
                    return;  
                }  
            });  
            alertDialog.show();
    } catch (Exception e) {
           e.printStackTrace();
    }
}
RajaReddy PolamReddy
  • 22,428
  • 19
  • 115
  • 166