Location>code7788 >text

Hongmeng without permission to realize the picture selection to take photos and record videos

Popularity:549 ℃/2024-11-21 12:15:49

In Hongmeng development, the system provides PhotoViewPicker to select pictures, cameraPicker to take pictures and record videos, this way can achieve no need to apply for permission from the user to select pictures, take pictures and record videos. In addition to user-operated picture selection, photo taking and video recording, other times APP has no right to get album pictures, no right to call the camera, for the user to use the album and the camera are very clear timing, security is very high. Take a look at the specific use of the following.

Selecting Images with the PhotoViewPicker

We new a PhotoViewPicker and call the select method, you can open the system image selector for image selection, support for a very large number of parameters, basically meet the daily use of the scene.

  • MIMEType: We can use MIMEType to set whether to select pictures or videos, or even select pictures and videos at the same time.
  • isEditSupported: use isEditSupported parameter to set whether to enter image editing mode after selecting an image.
  • isOriginalSupported: set whether the selected image is a source image by isOriginalSupported parameter, the parameter is set to true, the selection page has a button to control whether to use the source image.
  • isPhotoTakingSupported: In the picture selection page, you can set whether the first position is a photo taking option or not by using the isPhotoTakingSupported parameter, and clicking on the first position after the setting, you can open the camera to take a picture.
  • isPreviewForSingleSelectionSupported: the isPreviewForSingleSelectionSupported parameter allows us to enter the big picture preview page after an image has been selected, enabling us to view more details of the image.
  • isSearchSupported: When there are too many pictures in the album, we can use the isSearchSupported parameter to display the search box, and enter the picture-related content in the search box in order to quickly find the relevant images
  • maxSelectNumber: set the number of selections by maxSelectNumber, the default selection is 50 pictures, the maximum selection is 500 pictures.
  • preselectedUris: when in multi-select mode, the preselectedUris parameter can be used to preselect some images, in order to avoid that every time you open the image selector, you have to re-select it, which will lead to the loss of the previously selected image.
    A complete example is as follows
new ().select({
  MIMEType: .IMAGE_TYPE,
  maxSelectNumber: 9,
  isEditSupported: false,
  isOriginalSupported: rue,
  preselectedUris: [],
  isPhotoTakingSupported: false,
  isPreviewForSingleSelectionSupported: false,
  isSearchSupported: false
}, (err, data) => {
  (data)
})

Taking pictures and recording videos with cameraPicker

We can use the select method of cameraPicker to take photo or record video, or we can set both photo and video recording at the same time, users can choose whether to take photo or record video on the photo page. The specific parameters are as follows

  • mediaTypes: is an array, set to take a picture, or record a video, or both.
  • cameraPosition: Set whether to use the front camera or the rear camera to take pictures or record videos.
  • saveUri: set the location where the photo or recorded video is saved, usually set to our sandbox directory
  • videoDuration: when the mode is record video, this parameter is to set the maximum duration of the video.
    A complete example is as follows
(context,[, ],
  { cameraPosition: .CAMERA_POSITION_BACK,saveUri:'',videoDuration:30 })
  .then((value) => {
    ()
  })

Users in the system to take pictures and record video page, you can choose a lot of parameters, such as whether to open the flash, the aspect ratio of the picture, the frame rate of the video, whether to tear the reference line and so on, there are a lot of parameters to choose from, the degree of flexibility is very high, basically to meet the daily use of scenarios, the most important thing is that there is no need to apply for permissions from the user, it's still very convenient.