PeeNpee PeePeen PeeNpee PeePeen - 3 months ago 9x
Java Question

android camera intent returns no data

I have a problem with obtaining data from on the 'onActivityResult' method after taking a picture from the camera intent.

Here is my method which is calling camera Intent:

private void __initCamera() {

String path = Environment.getExternalStorageDirectory() + "/vault/images/";

File dir = new File(path);
if (!dir.exists()) {
dir = new File(path);
String[] content = dir.list();
String fileName = (content.length + 1) + ".jpg";
File file = new File(path, fileName);
if (!file.exists()) {
try {
} catch (IOException ex) {
Log.e("my_app", ex.getMessage());

Uri uri = Uri.fromFile(file);
Intent i = new Intent("");
i.putExtra(MediaStore.EXTRA_OUTPUT, uri);
startActivityForResult(i, 8765);

Here is my onActivityResult method:

-1(should be: 1, right?),

exception: No content provider: #Intent;action=inline-data;end

data.toURI() :

protected void onActivityResult(int requestCode, int returnCode, Intent data) {

try {

Bitmap bitmap = Media.getBitmap(getContentResolver(), Uri.parse(data.toURI()));
FileOutputStream out = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 50, out);
} catch (Exception ex) {
Log.e("TROLL", ex.toString());



Bitmap bitmap = Media.getBitmap(getContentResolver(), Uri.parse(data.toURI()));

Should be this:

Bitmap bitmap = (Bitmap) data.getExtras().get("data"); 

At least, that's how I normally retrieve images. Also, I would recommend checking for the correct request code instead of using an all encompassing Exception there.