Skip to content

Instantly share code, notes, and snippets.

@jakemoore
Created November 6, 2011 05:33
Show Gist options
  • Save jakemoore/1342523 to your computer and use it in GitHub Desktop.
Save jakemoore/1342523 to your computer and use it in GitHub Desktop.
private class SaveSnapshotTask extends AsyncTask<Void, Void, File> {
@Override
protected void onPreExecute() {
View progress = findViewById(R.id.progress);
progress.setVisibility(View.VISIBLE);
}
@Override
protected File doInBackground(Void... ignore) {
File pictureFile = getOutputMediaFile();
if (pictureFile == null){
Log.d(TAG, "Error creating media file, check storage permissions");
return null;
}
try {
FileOutputStream fos = new FileOutputStream(pictureFile);
mCurrentBmp.compress(Bitmap.CompressFormat.JPEG, 85, fos);
fos.close();
// String uri = MediaStore.Images.Media.insertImage(getContentResolver(),
// pictureFile.getAbsolutePath(), pictureFile.getName(), pictureFile.getName());
} catch (FileNotFoundException e) {
Log.d(TAG, "File not found: " + e.getMessage());
pictureFile = null;
} catch (IOException e) {
Log.d(TAG, "Error accessing file: " + e.getMessage());
pictureFile = null;
}
return pictureFile;
}
@Override
protected void onPostExecute(File file) {
View progress = findViewById(R.id.progress);
progress.setVisibility(View.GONE);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment