Created
September 19, 2013 17:05
-
-
Save jsam/6626531 to your computer and use it in GitHub Desktop.
saving async task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Async class for communication with I/O for saving taken photo | |
* @param jpeg byte representation of given photo for saving to filesystem | |
*/ | |
class SavePhotoTask extends AsyncTask<byte[], String, String> { | |
@Override | |
protected String doInBackground(byte[]... jpeg) { | |
UUID image_name = UUID.randomUUID(); | |
File photo = new File(Environment.getExternalStorageDirectory(), | |
PICTURES_DIR + image_name.toString()); | |
if (photo.exists()) { | |
photo.delete(); | |
} | |
try { | |
FileOutputStream fos = new FileOutputStream(photo.getPath()); | |
fos.write(jpeg[0]); | |
fos.close(); | |
} | |
catch (java.io.IOException e) { | |
Log.e("PictureDemo", "Exception in photoCallback", e); | |
} | |
return(null); | |
} | |
} | |
if (imageBytes != null) { | |
new SavePhotoTask().execute(imageBytes); | |
Toast.makeText(getApplicationContext(), | |
"Saving photo to Images folder.", | |
Toast.LENGTH_LONG); | |
} | |
else { | |
Toast.makeText(getApplicationContext(), | |
"There's nothing to save", | |
Toast.LENGTH_LONG); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment