Closed calleja23 closed 3 years ago
Hi thanks for the plugin. I am having problems activating the flash on my phone. The function does not give an error. But it doesn't work either I attach more information: Its a ng-app
{ "nativescript": { "id": "com.app.myApp", "tns-ios": { "version": "6.5.2" }, "tns-android": { "version": "6.5.3" } }, "description": "NativeScript Application", "license": "SEE LICENSE IN <your-license-filename>", "repository": "<fill-your-repository-here>", "dependencies": { "@angular/animations": "~8.2.0", "@angular/common": "~8.2.0", "@angular/compiler": "~8.2.0", "@angular/core": "~8.2.0", "@angular/forms": "~8.2.0", "@angular/platform-browser": "~8.2.0", "@angular/platform-browser-dynamic": "~8.2.0", "@angular/router": "~8.2.0", "@nativescript/theme": "~2.2.1", "@nstudio/nativescript-camera-plus": "^3.2.2", "log4js": "^6.3.0", "nativescript-angular": "~8.20.3", "nativescript-aws-sdk": "0.0.4", "nativescript-background-http": "^4.2.1", "nativescript-barcodescanner": "^3.4.2", "nativescript-downloader": "^2.1.5", "nativescript-geolocation": "^5.1.0", "nativescript-mediafilepicker": "^3.0.2", "nativescript-orientation": "^2.2.5", "nativescript-plugin-firebase": "^10.6.3", "nativescript-webview-interface": "^1.4.3", "nativescript-wifi-info": "0.0.5", "nativescript-zip": "^4.0.2", "reflect-metadata": "~0.1.12", "rxjs": "^6.6.3", "tns-core-modules": "^6.5.24", "zone.js": "~0.9.1" }, "devDependencies": { "@angular/compiler-cli": "~8.2.0", "@ngtools/webpack": "~8.2.0", "@types/node": "^14.14.7", "nativescript-dev-webpack": "~1.5.1", "typescript": "~3.5.3" }, "readme": "NativeScript Application" }
my camera.component.ts
import { Component, NgZone, OnDestroy, OnInit ,ChangeDetectorRef,ChangeDetectionStrategy} from '@angular/core'; import { ImageAsset } from '@nativescript/core/image-asset'; import { ImageSource } from '@nativescript/core/image-source'; import { CameraPlus } from '@nstudio/nativescript-camera-plus'; import {screen} from "tns-core-modules/platform/platform" import { Location } from "@angular/common"; import * as orientations from "nativescript-orientation"; import {getString,setString,remove,clear} from "tns-core-modules/application-settings"; import * as bgHttp from "nativescript-background-http"; var bindingDist; @Component({ selector: 'ns-capture', moduleId: module.id, templateUrl: './camera.component.html', styleUrls:['./camera.component.css'], changeDetection:ChangeDetectionStrategy.OnPush }) export class CameraComponent implements OnInit, OnDestroy { private cam: CameraPlus; public imageSource: ImageSource; public size= screen.mainScreen.heightDIPs-177; public events: { eventTitle: string, eventData: any }[] = []; public cameraVisible= true; public saveToGallery=true; public isRecording= false; public enableVideo=false; public fileName; public totalUpload public buttoninteraction =true public tasks: bgHttp.Task[] = []; public totalUploadpercent public progress lastEvent = ""; constructor(private zone: NgZone,public location:Location, public detector:ChangeDetectorRef,) { orientations.setOrientation("portrait") orientations.disableRotation(); let video = getString("PHOTO") let videoName= getString("PHOTO") if(video && videoName){ remove(video) remove(videoName) } bindingDist=this.detector.detectChanges; } ngOnInit(): void {} ngOnDestroy() {} public camLoaded(e: any): void { console.log('***** cam loaded *****', new Date().toString()) this.cam = e.object as CameraPlus; let isPermmitCam= this.cam.hasCameraPermission(); if(!isPermmitCam){ this.cam.requestCameraPermissions().then((permission)=>{ console.log("[permission]",permission) }).catch((error)=>{ console.log("[error]",error) }) }else{ } } public toggleCameraEvent(e: any): void { } public takePicFromCam(){ this.cam.takePicture({width: 150, height: 150, keepAspectRatio: true, saveToGallery: false }); } public photoCapturedEvent(e:any): void { new ImageSource().fromAsset(e.data as ImageAsset).then(result => { const base64String = result.toBase64String("png"); console.log('PHOTO CAPTURED base64String!!!',base64String); setString("PHOTO",base64String); this.goToHome(base64String) }); } public goToHome(event){ ((this.isRecording==true)?this.cam.stop():this.isRecording=false) orientations.enableRotation(); this.location.back() } public imagesSelectedEvent(e: any): void { new ImageSource().fromAsset((e.data as ImageAsset)[0]).then(result => { const base64String = result.toBase64String("png"); console.log('IMAGES SELECTED EVENT!!!--3',base64String); setString("PHOTO",base64String); this.goToHome(base64String) }); } public takeApphoto(event){ console.log("[takeApphoto]",event.data) let isPermmitCam= this.cam.hasCameraPermission(); if(!isPermmitCam){ this.cam.requestCameraPermissions().then((permission)=>{ console.log("[permission-camera]",permission) }).catch((error)=>{ console.log("[error]",error) }) }else{ this.cam.takePicture({ width: 150, height: 150, keepAspectRatio: true, saveToGallery: false }); } } public toggleFlash(){ console.log("[toggleFlash]") let isPermmitCam= this.cam.hasCameraPermission(); if(!isPermmitCam){ this.cam.requestCameraPermissions().then((permission)=>{ let isFlashmode= this.cam.getFlashMode(); console.log("[permission-isFlashmode]",isFlashmode) if(isFlashmode=="off"){ this.cam.toggleFlash(); console.log("[permission-isFlashmode-changed]",this.cam.getFlashMode()) } }).catch((error)=>{ console.log("[error]",error) }) }else{ console.log("[permission-camera-flash]",isPermmitCam) let isFlashmode= this.cam.getFlashMode(); console.log("[permission-isFlashmode]",isFlashmode) if(isFlashmode=="off"){ this.cam.toggleFlash(); console.log("[permission-isFlashmode-changed]",this.cam.getFlashMode()) } } } public openCamPlusLibrary(event){ console.log("[openCamPlusLibrary]",event) let isPermmitCam= this.cam.hasStoragePermissions(); if(!isPermmitCam){ this.cam.requestStoragePermissions().then((permission)=>{ console.log("[permission-openCamPlusLibrary]",permission) this.cam.chooseFromLibrary(); }).catch((error)=>{ console.log("[error]",error) }) }else{ this.cam.chooseFromLibrary(); } } }
attach my logcat.txt logcat.txt
Thanks!
fixed: https://github.com/nstudio/nativescript-camera-plus/commit/568c2a995d31d43818521e5cb4ffc32f535e80ca
Hi thanks for the plugin. I am having problems activating the flash on my phone. The function does not give an error. But it doesn't work either I attach more information: Its a ng-app
my camera.component.ts
attach my logcat.txt logcat.txt
Thanks!