Use Android cam app in our Application

General topics about the Android-Platform itself.
Coding issues please to the subforum right below.

Use Android cam app in our Application

Postby bins1984 » Tue May 04, 2010 6:59 am

Hi,

We can take Picture using android Default Camera Application in androids and use the captured image in our application Using Media Store Content provider API.
Here I am i will mention the Code to start the Camera Intent using MediaStore Content Provider.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.     @Override
  2.  
  3.                                 public void onClick(View v) {
  4.  
  5.                                         Intent intent2= new Intent("android.media.action.IMAGE_CAPTURE");
  6.  
  7.                                         startActivityForResult(intent2,INTENTCODE);
  8.  
  9.                                        
  10.  
  11.                                 }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


And write code to receive the Captured image in OnActiviy Result


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. @Override
  2.  
  3.     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  4.  
  5.         // TODO Auto-generated method stub
  6.  
  7.         super.onActivityResult(requestCode, resultCode, data);
  8.  
  9.        
  10.  
  11.         if (resultCode != RESULT_OK) {
  12.  
  13.                         return;
  14.  
  15.                 }else{
  16.  
  17.                 Bitmap temp= (Bitmap)data.getExtras().get("data");
  18.  
  19.                 mImageView.setImageBitmap(leftImage);
  20.  
  21.                 }
  22.  
  23.     }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4



If You need to Name your Image you can use this method to satrt Acivity

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Intent intent2= new Intent("android.media.action.IMAGE_CAPTURE");
  2.  
  3.                                         Uri uri = Uri.fromFile(new File("tempImage"));
  4.  
  5.                                         intent2.putExtra(MediaStore.EXTRA_OUTPUT,uri);
  6.  
  7.                                         startActivityForResult(intent2,INTENTCODE);
Parsed in 0.035 seconds, using GeSHi 1.0.8.4



Cheers..

Bins.......... :)
User avatar
bins1984
Experienced Developer
Experienced Developer
 
Posts: 67
Joined: Fri Feb 08, 2008 8:20 am
Location: India

Top

Postby bins1984 » Tue May 04, 2010 12:16 pm

Hi

If we use this in Android 1.6 onwards we have to keep data like this

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Intent intent2= new Intent("android.media.action.IMAGE_CAPTURE");
  2.  
  3. uri=Uri.fromFile(new File("/sdcard/TempPicture.jpg"));
  4.  
  5. intent2.putExtra(MediaStore.EXTRA_OUTPUT,uri);
  6.  
  7. startActivityForResult(intent2,0);
Parsed in 0.036 seconds, using GeSHi 1.0.8.4



On Activity result we can get image like this way

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  2.  
  3.    
  4.  
  5.         super.onActivityResult(requestCode, resultCode, data);
  6.  
  7.        
  8.  
  9.         if (resultCode != RESULT_OK) {
  10.  
  11.                         return;
  12.  
  13.                 }else{
  14.  
  15.                         Bitmap Image = null;
  16.  
  17.                         try {
  18.  
  19.                                 Image = MediaStore.Images.Media.getBitmap(getContentResolver(),uri);
  20.  
  21.                         } catch (FileNotFoundException e) {
  22.  
  23.                        
  24.  
  25.                                 e.printStackTrace();
  26.  
  27.                         } catch (IOException e) {
  28.  
  29.                                 // TODO Auto-generated catch block
  30.  
  31.                                 e.printStackTrace();
  32.  
  33.                         }
  34.  
  35.                        
  36.  
  37.                 mImageView.setImageBitmap(Image);
  38.  
  39.                 }
  40.  
  41.     }
Parsed in 0.037 seconds, using GeSHi 1.0.8.4



cheers

Bins..... :)
User avatar
bins1984
Experienced Developer
Experienced Developer
 
Posts: 67
Joined: Fri Feb 08, 2008 8:20 am
Location: India

Postby Boni2k » Wed May 05, 2010 5:26 pm

Hello,

I tried the second method some months ago and found it to be very unstable. Sometimes it didn't resolve in a result so onActivityResult() was never called. But I'll try again... Using the first method you would only get a picture with reduced quality, which is not what the user wants. While the resolution in 2.1 is quite okay it was very bad on older android versions. The Facebook app e.g. ignored this.
Boni2k
Experienced Developer
Experienced Developer
 
Posts: 88
Joined: Sun Dec 20, 2009 9:46 pm

Re: Use Android cam app in our Application

Postby theblang » Tue May 18, 2010 11:10 pm

Thanks a lot for posting this! I am currently able to call the default camera app no problem; however, when I take a picture two buttons pop up (attach and cancel). Were you able to send the picture data back immediately after taking a picture rather than having to click a confirmation button?
theblang
Junior Developer
Junior Developer
 
Posts: 15
Joined: Tue May 18, 2010 9:37 pm

Re: Use Android cam app in our Application

Postby Boni2k » Tue May 18, 2010 11:41 pm

theblang wrote:Thanks a lot for posting this! I am currently able to call the default camera app no problem; however, when I take a picture two buttons pop up (attach and cancel). Were you able to send the picture data back immediately after taking a picture rather than having to click a confirmation button?

No, that doesn't work using this method.
Boni2k
Experienced Developer
Experienced Developer
 
Posts: 88
Joined: Sun Dec 20, 2009 9:46 pm

Top

Return to General

Who is online

Users browsing this forum: No registered users and 8 guests