• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps taking a picture with native camera and saving

Hey guys, I am trying to take a picture with the phones native camera app and store it but for some reason it is not working... can someone help?

Code:
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]protected[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] startCameraActivity()
{
Log.[I]i[/I]([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"MakeMachine"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"startCameraActivity()"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] );
File imageFile = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] File(Environment.[I]getExternalStorageDirectory[/I]().toString()+[/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"/image.jpg"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
Uri outputFileUri = Uri.[I]fromFile[/I](imageFile);

Intent intent = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Intent(android.provider.MediaStore.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]ACTION_IMAGE_CAPTURE[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
intent.putExtra(MediaStore.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]EXTRA_OUTPUT[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], outputFileUri);

startActivityForResult( intent, 0 );
}

[/SIZE][SIZE=2][COLOR=#646464][SIZE=2][COLOR=#646464]@Override[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]protected[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] onActivityResult([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] requestCode, [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] resultCode, Intent data) 
{ 
Log.[I]i[/I]( [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"MakeMachine"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"resultCode: "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + resultCode );
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]switch[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]( resultCode )
{
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]case[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] 0:
Log.[I]i[/I]( [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"MakeMachine"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"User cancelled"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] );
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]break[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];

[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]case[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] -1:
onPhotoTaken();
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]break[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
}
}

[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]protected[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] onPhotoTaken()
{
Log.[I]i[/I]( [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"MakeMachine"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"onPhotoTaken"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] );

[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]_taken[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]true[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];

BitmapFactory.Options options = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] BitmapFactory.Options();
[/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//options.inSampleSize = 4;[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]
Bitmap bitmap = BitmapFactory.[I]decodeFile[/I](Environment.[I]getExternalStorageDirectory[/I]().toString()+[/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"/image.jpg"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], options);

[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]_image[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].setImageBitmap(bitmap);

[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]_field[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].setVisibility(View.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]GONE[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/LEFT]
}
[/SIZE]

When I go and look at bitmap's value during debugging it is null.
 
Back
Top Bottom