0

@Override

protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    super.onActivityResult(requestCode, resultCode, data);
    Bundle bundle=data.getExtras();
    Bitmap bitmap=(Bitmap)bundle.get("data");
    iv1.setImageBitmap(bitmap);
}

Actually,i m capturing photo using camera and then calling startActivityForResult()

How can i save this photo into my phone's internal storage and then use it whenever i want....

Thank u in advance

Anubhav Singh
  • 8,321
  • 4
  • 25
  • 43

1 Answers1

0

use below function in your activity

@Override

protected void onActivityResult(int requestCode, int resultCode, Intent data){
   super.onActivityResult(requestCode, resultCode, data);
   Bundle bundle=data.getExtras();
   Bitmap bitmap=(Bitmap)bundle.get("data");
   iv1.setImageBitmap(bitmap);
   SaveBitmap(bitmap) 
}

private void SaveBitmap(Bitmap finalBitmap) {
   String sdCard = Environment.getExternalStorageDirectory().toString();
   File myDir = new File(sdCard + "/app_name");    
   myDir.mkdirs(); // creating dir
   String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); // creating a unique file name 

   String fname = "IMG"+ timeStamp +".jpg";
   File file = new File (myDir, fname);
   if (file.exists ()) file.delete (); // del file filr if already exists
   try {
      FileOutputStream out = new FileOutputStream(file);
      finalBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
      out.flush();
      out.close();
   } catch (Exception e) {
      e.printStackTrace();
   }
}
sajan
  • 389
  • 5
  • 11