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