0

I'm trying to take a picture with the camera Intent and then immediately set the activity background to that image.

@SuppressWarnings("deprecation")
public void TakePictureIntent() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        File photoFile = null;
        try {
            photoFile = SavePicture();
        } catch (IOException ex) {
            return;
        }
        if (photoFile != null) {
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                    Uri.fromFile(photoFile));
            startActivityForResult(takePictureIntent, 1);
            RelativeLayout rl = (RelativeLayout)findViewById(R.id.activity_layout);
            Bitmap bitmap = BitmapFactory.decodeFile(photoFile.getAbsolutePath());
            Drawable dr = new BitmapDrawable(bitmap);
            rl.setBackgroundDrawable(dr);
        }
    }
}

Just looking at my code, it doesn't look correct. Too much conversions from classes.

How would I go about doing this?

  • The last 4 lines of your code should be in the `onActivityResult` method. But what exactly is the problem you're encountering? – ashishduh May 09 '14 at 19:30
  • The code just doesn't do anything. It returns no errors and the app runs without crashing though. – spamelot May 09 '14 at 20:21
  • So the camera doesn't even launch? If the camera doesn't even launch then `photoFile` is probably always null, you haven't shown us the `SavePicture` code. – ashishduh May 09 '14 at 21:00

1 Answers1

0

Check similar StackOverflow solution on that issue. I think you are looking for a complete solution on this issue. If so, this article would be good one for you:

Community
  • 1
  • 1
ridoy
  • 6,274
  • 2
  • 29
  • 60