The NativeScript error code TS2554 is indicating an expectation of 1 argument, however, none were provided

Trying to utilize the native camera API with NativeScript without any plugins has presented an error when attempting to use the takePicture function:

app/shared/camera/camera.service.ts(23,39): error TS2554: Expected 1 argument, but received 0. app/shared/camera/camera.service.ts(23,84): error TS1005: ',' expected.

     import { Injectable} from '@angular/core';
     import * as permissions from 'nativescript-permissions';
     @Injectable()

     export class CameraService  {
       Camera:any; //Camera android.hardware.Camera instantiation
       camera:any;
       constructor() {
         let CAMERA = () => (android as any).Manifest.permission.CAMERA;
       let RECORD_AUDIO = () => (android as any).Manifest.permission.RECORD_AUDIO;
       let READ_EXTERNAL_STORAGE = () => (android as any).Manifest.permission.READ_EXTERNAL_STORAGE;
       let WRITE_EXTERNAL_STORAGE = () => (android as any).Manifest.permission.WRITE_EXTERNAL_STORAGE;
         this.Camera=android.hardware.Camera; 
         this.camera = android.hardware.Camera;
        }  
       CamList = [];
       //start up the camera
       startup(cameraID:number){
try{
         this.Camera.open(cameraID);
         this.Camera.startPreview();
         this.Camera.takePicture(null,null,new android.hardware.Camera.PictureCallback(){
            onPictureTaken:async (data,camera)=>{
              this.releasecamera();
              this.sendpicture(data);
            }
          });
         }catch(ex){
           console.log('startup error',ex);
}
      }
       //send picture
     sendpicture(data){
let bitmap = android.graphics.BitmapFactory.decodeByteArray(data,0,data.length);
let outputStream = new java.io.ByteArrayOutputStream();
bitmap.compress(android.graphics.Bitmap.CompressFormat.JPEG, 100, outputStream);
let img=[];
img.push({image:true,buffer:outputStream.toByteArray()});

      }
      //list all cameras available on the device
      getcameras(){
       // let Camera:any = android.hardware.Camera ; 
        let numberOfcams = this.Camera.getNumberOfCameras();                                  //android.hardware.Camera.getNumberOfCameras();

for(let i = 0 ; i<numberOfcams;i++){
          let camera = new this.Camera.CameraInfo();
          this.Camera.getCameraInfo(i,camera);
          if(camera.facing == this.Camera.CameraInfo.CAMERA_FACING_FRONT)
            {
              //let ca = "{name:'front' , id:"+i+"}";
              this.CamList.push({name:'front',id:i});
            }else if(camera.facing == this.Camera.CameraInfo.CAMERA_FACING_BACK)
            {
             // let ca = "{name:'back' , id:"+i+"}";
              this.CamList.push({name:'back',id:i});
            }  else{
              this.CamList.push({name:'other',id:i});
            }
            console.dir(this.Camera.getCameraInfo(i,camera));
}
//console.dir(this.CamList);

return this.CamList ;
      }
       //release camera
    releasecamera(){
if(this.camera != null ){
  this.camera.stopPreview();
  this.camera.release();
  this.camera=null;
}
       }


     }

Answer №1

How can I improve this code?


        To capture a picture, use the following code snippet in your Android app:

        this.Camera.takePicture(null, null, new android.hardware.Camera.PictureCallback({
            onPictureTaken: async (data, camera) => {
                Don't forget to release the camera using this.releasecamera();
                Then, send the captured picture using this.sendpicture(data);
            }
        }));

If you need more information on extending interfaces, check out the documentation here

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Optimal Strategies for Handling CORS in Angular 2+ and Node/Express Servers

Currently, I am in the process of implementing user authentication with Express/Node and testing cookies from an Angular frontend. Upon logging in, the cookies are properly displayed in the network tab but not in the application tab. I understand that usi ...

Encountered an issue at line 19, column 13: Unable to locate resource: javax.annotation:jsr250-api:1

Currently, I am working on a project that involves adding Dagger2 dependency. Below is the snippet of my build.gradle file: buildscript { repositories { mavenCentral() jcenter() } dependencies { classpath 'com.andr ...

The Device does not support the decodeHex method, however, it is functioning properly on the Emulator

I am currently working on a project involving RSA encryption and have been utilizing the methods provided by Apache commons-codec. These methods include: Hex.encodeHex(byte[]) Hex.decodeHex(String) While both methods are functioning correctly on the And ...

The credentials in AWS S3Client are failing to load correctly

I encountered an issue with the S3 Client from aws sdk v3: When using the S3Client as outlined in the documentation and providing credentials via environment variables, I received an error message stating The AWS Access Key Id you provided does not exist ...

Two users are concurrently updating data in a MySQL table

I am currently developing an online game Android app using PHP as the server-side technology. I have encountered an issue that I am unable to resolve at the moment. My goal is to have two users play a game together when they are both online and connecting ...

Whenever you tap on a BottomNavigationBar item, a new instance is generated while preserving the previous one in the backstack

I am currently utilizing the Android navigation component along with BottomNavigationBar in my app. My Approach In order to organize my application, I have established four tabs each with its own separate navigation graph. Additionally, I have a dedicate ...

Angular integrates a user-friendly help file feature that includes helpful information and instructions for

I am looking to streamline my code by storing help text in a separate file using key value pairs. This will allow me to easily reference them next to form labels on different components. To achieve this, I have created an app-config.ts file and utilized @ ...

do not proceed with instructions

i designed this directive to handle user permission validation for displaying or hiding menu items on the page here is my implementation: @Directive({ selector: '[Permission]' }) export class PermissionDirective { @Input() Acc ...

Caution: Potential issue observed when utilizing Enzyme within beforeEach in a Typescript environment

Presently, here is my code snippet: const MyComponent = () => ( <Provider store={storeRedux}> <BrowserRouter> <Context.Provider value={...}}> <Mode { ...props } /> </Context.Provider> </Br ...

Angular 9: NgbModal is auto-navigating upon initialization

Encountering difficulties with loading two modals (openModalEdit and openModalDetail method) in my Angular 9 project. Upon opening, it automatically redirects to the root route. There is another modal instance (openModalCreate method) in the same componen ...

Tips for extracting a list of text from a view with the help of robotium

I'm currently working on automating the testing of an Android app using Robotium. My goal is to extract a list of text from a view using Robotium for an Android device. Is there anyone who can assist me with this task? ...

What types should you use for an Axios response in React and TypeScript?

Trying to display a basic user list fetched from an API, which returns the following data: [{"UserID":2,"FirstName":"User2"},{"UserID":1,"FirstName":"User1"}] Struggling to understand how to deal ...

What is responsible for the background of the Textview?

In my current layout, I have structured it in the following way: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layo ...

using Typescript in an Angular2 application

Can anyone explain why I am receiving an error when attempting to declare a const? The error message states: Expecting new line or semicolon export class MyClass{ const ALLOC_INVESTORS = "Allocation Investors"; } ...

Http' does not have the 'update' property

I recently implemented Angular 2 Release and utilized 'Http' from '@angular/http' for my project. However, I encountered an error when I invoked the method 'update', which resulted in the following message: "Evidently, th ...

Generating a dynamic clickable div using Angular 6

How can I create a user-friendly interface that displays an image with clickable divs around detected faces, allowing users to view specific attributes for each face? I'm looking for a solution where I can have divs or buttons around each face that t ...

Tips for changing the color of an icon when clicking a button

How can I dynamically change the color of an icon when clicked? Would using ngClass be the most efficient approach for this task? Currently, I have assigned a class to my icon. <ion-card> <ion-row> <ion-col> < ...

Error encountered due to file locking conflict following upgrade to Gradle version 3.0.1

After upgrading to Android Gradle 3.0.1, I encountered this exception in my multimodule android project where I am using Jacoco. java.nio.channels.OverlappingFileLockException at sun.nio.ch.SharedFileLockTable.checkList(FileLockTable.java:255) at sun.nio. ...

Invoking the same AsyncTask multiple times when a button is clicked in an adapter class

I am facing an issue with my AsyncTask in the adapter class. It works fine the first time I call it, but for some reason, it doesn't work the second time. I understand that when we need to call the same task multiple times in an activity class, we ha ...

Access a server using Android version 5.1.1

I am encountering an issue with connecting to a server on certain versions of Android. Below is the code snippet from my class: URL url = new URL("http://1-dot-f4nt4c4lc10c0mmun1ty.appspot.com/login"); URLConnection connection = url.openConnection(); Str ...