I've been struggling with trying to figure out how to take a photo using an android device, and having that photo be uploaded to Parse.com. I'm obviously doing something wrong, as all I'm getting is the thumbnail image.
I've been searching Google, and have run across some very confusing/convoluted ways of doing what I'm after (I think?), but I was assume that if getting the thumbnail is so easy, why should getting the full image be so different or difficult?
EDIT: I'm thinking the main issue is that fileUri is null when I look at the variable in onActivityResult. This seems to be common on certain devices. I'm using an old Droid and a genymotion emulator running a Galaxy S5. Perhaps that's my issue?
Here's my code:
public void takePhoto() {
// Check Camera
if (getApplicationContext().getPackageManager().hasSystemFeature(
PackageManager.FEATURE_CAMERA)) {
// Open default camera
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
// start the image capture Intent
startActivityForResult(intent, 100);
} else {
Toast.makeText(getApplication(), "Camera not supported", Toast.LENGTH_LONG).show();
}
}
and that part works fine, and here's the onActivityResult:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
byte[] image_byte_array;
if (data != null) {
if (requestCode == 100 && resultCode == RESULT_OK) {
Toast.makeText(getApplicationContext(), "Saving File...", Toast.LENGTH_LONG).show();
Bitmap photo = (Bitmap) data.getExtras().get("data");
ByteArrayOutputStream stream = new ByteArrayOutputStream();
photo.compress(Bitmap.CompressFormat.JPEG, 100, stream);
image_byte_array = stream.toByteArray();
ParseFile photo = new ParseFile("photo.jpg", image_byte_array);
ParseObject parseObject = new ParseObject("Items");
parseObject.put("photo", photo);
parseObject.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
if (e != null) {
Toast.makeText(getApplicationContext(), "Error: " + e.toString(), Toast.LENGTH_LONG).show();
} else {
}
}
});
photo.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
if (e != null) {
Toast.makeText(getApplicationContext(), "Error: " + e.toString(), Toast.LENGTH_LONG).show();
} else {
Log.i("ParseFile", "--- File is Saved ---");
}
}
});
} else {
finish();
}
}
}
The code above works perfectly fine, but as mentioned previously, it just creates and uploads a small 5k thumbnail jpg graphic. I want the full image. I realize I'll have to scale it down before uploading, but I'll work on that once I figure out how to gain access to the main image.
I have the appropriate Manifest entries for READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE. Also, I don't even need the image once it's done uploading.
What am I missing?