HerickRaposo opened a new issue #721: URL: https://github.com/apache/cordova-plugin-camera/issues/721
# 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 <!-- Include all relevant information that might help understand and reproduce the problem --> 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](https://cordova.apache.org/docs/en/dev/guide/platforms/android/index.html#what-makes-android-different) 2. [Ionic cordova-plugin-camera crash the application after take picture](https://github.com/apache/cordova-plugin-camera/issues/705) 3. [App crashes after taking photo from camera](https://forum.ionicframework.com/t/app-crashes-after-taking-photo-from-camera/100754) 4. [Native camera ionic make app crash after taking picture](https://stackoverflow.com/questions/49208695/native-camera-ionic-make-app-crash-after-taking-picture) 5. [Camera plugin crashes app on some android phones when an image is taken](https://github.com/apache/cordova-plugin-camera/issues/345) end others ### Command or Code <!-- What command or code is needed to reproduce the problem? --> 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 <!-- In what environment, on what platform or on which device are you experiencing the issue? --> 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 <!-- What are relevant versions you are using? For example: Cordova: Cordova CLI, Cordova Platforms, Cordova Plugins Other Frameworks: Ionic Framework and CLI version Operating System, Android Studio, Xcode etc. --> ``` 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 ``` ## Checklist <!-- Please check the boxes by putting an x in the [ ] like so: [x] --> - [x] I searched for existing GitHub issues - [x] I updated all Cordova tooling to most recent version - [x] I included all the necessary information above -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
