Using Intent to start camera and take pictures problem.

All your problems with Audio, Video and Images.

Using Intent to start camera and take pictures problem.

Postby djandreski » Thu Oct 14, 2010 9:55 am

Hi guys. Good old camera problem, but hope someone figured out by now.
So here is the code that I'm using to take pictures with the pre-installed camera app.

The code that start the activity with the intent.
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public void onTakePhotoClickHandler(View v){
  2.         m_Intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE, null);
  3.         m_Intent.putExtra(MediaStore.EXTRA_OUTPUT,
  4.             MediaStore.Images.Media.EXTERNAL_CONTENT_URI.toString()); // <- For big picture save
  5.         startActivityForResult(m_Intent, TAKE_PICTURE);
  6.     }
  7.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


The onActivityResult() implementation
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. @Override
  2.     protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
  3.         if (resultCode == RESULT_CANCELED) { // <- resultCode = -1 (in debug watch)
  4.             return;
  5.         }
  6.         switch (requestCode) {
  7.  
  8.         case TAKE_PICTURE:
  9.             Bundle b = intent.getExtras();
  10.             Bitmap bm = (Bitmap) b.get("data"); // This is the photo <- bm.mHeight = -1 and bm.mWidth = -1 (in debug watch)
  11.            
  12.             if (b.containsKey(MediaStore.EXTRA_OUTPUT)) { // <- this condition is FALSE
  13.                 // Should have to do nothing for big images -- should already saved in MediaStore ... but
  14.                 saveImageAndThumbnails(bm);
  15.             }
  16.             else{
  17.                 super.onActivityResult(requestCode, resultCode, intent);
  18.             }
  19.             break;
  20.         }
  21.  
  22.     }
  23.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


As you can see the problem is that onActivityResult() resultCode is -1 probably there isn't extra data in the returning Intent so there can't be Bitmap pulled out of that data. And the contrition in the "if" command if(b.containsKey(MediaStore.EXTRA_OUTPUT)) is false.

So any clue what I am missing here?

This code is copy-pasted from this tutorials:
http://2009.hfoss.org/Tutorial:Camera_and_Gallery_Demo
http://2009.hfoss.org/Tutorial:Camera/Gallery_Part_II
which are a bit outdated but but still works when I run it. All the examples I've seen use this approach?

So what are my opinions on this:
1. I think that there is something about the Uri passed in the Intent's extra data.
2. Maybe something is happening in the onResume() method when the calling activity is displayed after the
camera app close and resets some variables.

So anyway I'm attaching the whole class where this code is placed(it is messy code :) but hey I need quick and working solution :twisted: no plans for maintenance)

TripDashBoard.java
(7.7 KiB) Downloaded 56 times
djandreski
Freshman
Freshman
 
Posts: 3
Joined: Thu Oct 14, 2010 9:05 am

Top

Re: Using Intent to start camera and take pictures problem.

Postby blundell » Thu Oct 14, 2010 1:20 pm

Tried it on a real device? The camera emiulation sucks
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Re: Using Intent to start camera and take pictures problem.

Postby djandreski » Thu Oct 14, 2010 1:51 pm

I tried but still nothing.

While I was surfing about this problem I find out that some versions of Android framework just don't accept MediaStore.EXTRA_OUTPUT in the Intent extra. So if it doesn't I need to put the Uri in the MediaStore that i pass into the Intent to start the camera Activity. And that is because Android can't pass data with the bigger than 50k
This sounds like a logical explanation, I'll try that later when I get back home (now I'm on my work PC).
So what do you think is this a possible solution?
djandreski
Freshman
Freshman
 
Posts: 3
Joined: Thu Oct 14, 2010 9:05 am

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: Exabot [Bot] and 17 guests