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:
-
- Public VoidStartintentforresult (){
-
- Intent intent =NewIntent (mediastore. action_image_capture );
-
- Intent. putextra (mediastore. extra_output, Uri. fromfile (mfile ));
- Startactivityforresult (intent, 1 );
-
- }
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.:
-
- Public VoidStartintent (){
- Intent intent = New Intent (mediastore. action_image_capture );
Startactivity (intent );
-
- }
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