android--start the camera function and return the results

Source: Internet
Author: User

A simple call to the system's camera function, the following code:

How to take pictures     private void opentakephoto () {         /**         *  before starting a photo shoot, it's best to decide if SDcard is available           */        String  State = environment.getexternalstoragestate ();    //get sdcard status codes available          if  (State.equals (environment.media_mounted)) {           //if available              Intent intent = new intent ("Android.media.action.IMAGE_CAPTURE");             startactivityforresult (Intent,take_photo);         }else {             toast.maketext (SettIngactivity.this, "SDcard not Available", Toast.length_short). Show ();         }     }

after taking the photos, we must take the photos we have taken and do some work. ( For example, Avatar, ribbon graph status, etc. ) , this time we need to rewrite the Onactivityresult () method, to get the photos we took to carry out the operation , we can go through the following two ways to get our photos, his addition is encapsulated in our inside the Intent, we just need to take it out:

@Override     protected void onactivityresult (int requestcode, int  resultcode, intent data)  {         Super.onactivityresult (Requestcode, resultcode, data);         if  (data!= null)  {             switch  (Requestcode)  {                 case take_photo:   //take pictures and choose                      //two ways    get a picture of a good shot                      if  (Data.getdata ()  != null | |  data.getextras ()  != null) {  //prevents no return result                          uri uri = data.getdata ();                         if  (uri !=  NULL)  {                             photo =  Bitmapfactory.decodefile (Uri.getpath ());    //Get Pictures                          }                          if  (photo == null)  {                             bundle bundle =  data.getextras ();                             if  (bundle !=  null)  {                                 photo  =  (Bitmap)  bundle.get ("Data");                             }  else {                                  Toast.maketext (Getapplicationcontext (),  "No picture Found",  toast.length_short). Show ();                             }                          }                        //Processing Pictures                         //cropping a picture                      }                     break;

of course, after the development The APP also needs a full range of tests:www.ineice.com


android--start the camera function and return the results

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.