taking a picture with native camera and saving


Last Updated:

  1. ninjasenses

    ninjasenses Active Member This Topic's Starter

    Joined:
    Feb 9, 2010
    Messages:
    38
    Likes Received:
    0
    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 (Text):
    1.  
    2. [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()
    3. {
    4. 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] );
    5. 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]);
    6. Uri outputFileUri = Uri.[I]fromFile[/I](imageFile);
    7.  
    8. 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]);
    9. intent.putExtra(MediaStore.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]EXTRA_OUTPUT[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], outputFileUri);
    10.  
    11. startActivityForResult( intent, 0 );
    12. }
    13.  
    14. [/SIZE][SIZE=2][COLOR=#646464][SIZE=2][COLOR=#646464]@Override[/LEFT]
    15. [/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)
    16. {
    17. 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 );
    18. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]switch[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]( resultCode )
    19. {
    20. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]case[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] 0:
    21. 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] );
    22. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]break[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
    23.  
    24. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]case[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] -1:
    25. onPhotoTaken();
    26. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]break[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
    27. }
    28. }
    29.  
    30. [/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()
    31. {
    32. 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] );
    33.  
    34. [/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];
    35.  
    36. BitmapFactory.Options options = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] BitmapFactory.Options();
    37. [/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//options.inSampleSize = 4;[/LEFT]
    38. [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]
    39. 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);
    40.  
    41. [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]_image[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].setImageBitmap(bitmap);
    42.  
    43. [/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]
    44. }
    45. [/SIZE]
    When I go and look at bitmap's value during debugging it is null.
     

    Advertisement

Share This Page

Loading...