asdasdApplication fails to take photos with the camera on some android devices

Bug Report

Problem

Application fails to take photos with the camera on some android devices

What is expected to happen?

It is expected that the application after capturing and selecting the preview image will be able to continue the return process without closing the application.

What does actually happen?

After taking the image capture and confirming the preview, the process is cut and the application is closed.
More specifically, when the application is in the background and the camera is accessed, after capturing, previewing and confirming, when trying to return to the application, the system ends the application process, therefore not being able to continue returning the image to the application

Information

According to research, the problem is due to a memory leak, however, the devices where the problem occurred do not lack this feature.
The problem so far has been encountered most frequently on Android Motorola devices. In my case, the problem was observed in the motoG7Play and MotoG8 phones.

Following instructions from Ionic and GitHub forums, I found some solutions like:

  1. enable cordova-plugin-background-mode before capture and disable after (Not Work in Redmi note 7)
  2. Add <preference name="AndroidLaunchMode" value="singleTask" /> in config.xml (Reduced cases in MotoG8)
  3. Set destinationType to DATA_URL, returning base64 format, later transforming the content into an image recorded on the device. (Dont work)

Search References

  1. Android Platform Guide
  2. Ionic cordova-plugin-camera crash the application after take picture
  3. App crashes after taking photo from camera
  4. Native camera ionic make app crash after taking picture
  5. Camera plugin crashes app on some android phones when an image is taken
    end others

Command or Code

I will show you the base codes (First code) and the codes of the aforementioned attempts.
Required plugins: cordova-plugin-file,cordova-plugin-ionic-webview,

Base Code:

getimage(op){
    const options: CameraOptions = {
      quality: 85, 
			destinationType: this.camera.DestinationType.FILE_URI,
			sourceType: (op == 1) ? this.camera.PictureSourceType.CAMERA : this.camera.PictureSourceType.PHOTOLIBRARY,
			encodingType: this.camera.EncodingType.JPEG,
			saveToPhotoAlbum: false,
			correctOrientation: true,

    }

    this.camera.getPicture(options).then((imagedata) => {
      let img = this.webview.convertFileSrc(imagedata)
      let imagemTratada = this.domSanatize.bypassSecurityTrustUrl(img)
      this.images.push(imagemTratada)
      if (this.platform.is('ios')) {
        this.caminhoImg.push(imagedata)
      } else {
        this.file.resolveLocalFilesystemUrl(imagedata).then((data)=>{
          this.caminhoImg.push(data.nativeURL);
        }).catch(error => console.log('error'))
      }
      this.verificaCondicao();
    })
  }

Second Code:

getimage(op){
    const options: CameraOptions = {
      quality: 85, 
			destinationType: this.camera.DestinationType.DATA_URL,
			sourceType: (op == 1) ? this.camera.PictureSourceType.CAMERA : this.camera.PictureSourceType.PHOTOLIBRARY,
			encodingType: this.camera.EncodingType.JPEG,
			saveToPhotoAlbum: false,
			correctOrientation: true,
    }

    this.camera.getPicture(options).then((imagedata) => {
      let base64 = 'data:image/jpeg;base64,' + imagedata;
      let blob = this.makeblob(base64);
      let image = this.domSanatize.bypassSecurityTrustUrl(base64)
      this.images.push(image)
      this.file.resolveDirectoryUrl(this.file.cacheDirectory).then((diretorio)=>{
        diretorio.getFile('Image' + Date.now() + '.jpg',{create:true}, (file)=> {
          console.log(file)
          file.createWriter((fileWriter)=>{
            fileWriter.write(blob)
            this.caminhoImg.push(file.nativeURL)
          },
          (error)=>{
            console.log('Unable to save file in path '+ diretorio.nativeURL);
          })
        })
      })
    })
  }

Environment, Platform, Device

The problem was found during the development of the application with ionic Framework and cord, based on the TypeScript Angular and using Android Studio 4.1 and sdk 28. The devices used for testing were Redmi note 7, iPed Pro, iPhone 5s, iPhone6, MotoG7Play, MotoG8, the camera bug only on the devices: MotoG7Play and MotoG8.

Version information

  Ionic CLI                     : 6.13.1 (C:\Users\micro-85\AppData\Roaming\npm\node_modules\@ionic\cli)
   Ionic Framework               : @ionic/angular 5.6.4
   @angular-devkit/build-angular : 0.1000.8
   @angular-devkit/schematics    : 10.0.8
   @angular/cli                  : 10.0.8
   @ionic/angular-toolkit        : 2.3.3

Cordova:

   Cordova CLI       : 10.0.0
   Cordova Platforms : android 9.1.0
   Cordova Plugins   : not available

Utility:

   cordova-res : 0.15.3
   native-run  : 1.3.0

System:

   NodeJS : v14.15.0 (C:\Program Files\nodejs\node.exe)
   npm    : 6.14.9
   OS     : Windows 10
 
Android:

  AndroidStudio:  4.1
  SDK :28

Bug report

I created bug report in: Application fails to take photos with the camera on some android devices