Call camera intent

Source: Internet
Author: User

When you call a camera, you sometimes need to return an image. Sometimes, you do not need to return an image.

Case 1,Call the camera in the app,Save the image to the specified directory., Returned to the app:

  1. Public VoidStartintentforresult (){
  2. Intent intent =NewIntent (mediastore. action_image_capture );
  3. Intent. putextra (mediastore. extra_output, Uri. fromfile (mfile ));
  4. Startactivityforresult (intent, 1 );
  5. }

In this intent, you must set action = mediastore. action_image_capture, and set the parameters mediastore. extra_output stores the captured image. This parameter sets the path for storing the image. Otherwise, the image cannot be found. Therefore, the storage path of this image should be a global variable to be taken out in onactivityresult.

Note: In Samsung Galaxy
In the device, the URI of the saved image needs to be obtained using intent. getdata (), instead of saving the image in the preset path !!!!!


Case 2, Call the camera in the app,The directory is not specified, but bitmap needs to be returned.:


  1. Public VoidStartintent (){
  2. Intent intent = New Intent (mediastore. action_image_capture );

    Startactivity (intent );
  3. }

Uri is empty because the image is encapsulated into the bundle and passed back.

Images need to be obtained in Bundle

Uri uri = data. getdata (); If (Uri! = NULL) {photo = bitmapfactory. decodefile (URI. getpath ();} If (photo = NULL) {bundle = data. getextras (); If (bundle! = NULL) {photo = (Bitmap) bundle. get ("data");} else {toast. maketext (defectmanageractivity. this, getstring (R. string. common_msg_get_photo_failure), toast. length_long ). show (); Return ;}}

In this caseBitmap to Uri,

 
Uri = URI. parse (mediastore. Images. Media. insertimage (getcontentresolver (), BMP, null, null ));

Case 3, Just open the camera, do not do any processing, andStay in the camera app and never go back to the app after taking a photoAnd save the photo to the default photo storage path:

Intent I = new intent (); I. setaction (mediastore. intent_action_still_image_camera); // stay in Carema

Another mediastore parameter is used here to enable the camera to automatically save images to the default system folder in normal shooting mode.

Note: The above two situations may also occur during video recording. You can refer to the above intent settings.

About class mediastore: http://developer.android.com/reference/android/provider/MediaStore.html

Related Article

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.