Camera extension will be developed if anyone know how to complete it

Can anyone utilize this code to make camera extension for android
This code provides several methods for working with the camera on Android, including:
Note there might be some errors in my code as I don’t have good coding experience.

openCamera() and releaseCamera(): open and release the camera object
startPreview() and stopPreview(): start and stop the camera preview
takePhoto(): take a photo using the camera and return the image data via the provided Camera.PictureCallback
startRecording() and stopRecording(): start and stop recording video using the camera
hasCamera() and hasFrontCamera(): check if the device has a rear or front-facing camera, respectively

Java :

package com.example;

import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.hardware.Camera;
import android.media.CamcorderProfile;
import android.media.MediaRecorder;
import android.os.Environment;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

import java.io.File;
import java.io.IOException;

public class CameraManager {
    private static final String TAG = "CameraManager";

    private Camera camera;
    private MediaRecorder mediaRecorder;

    public CameraManager() {}

    public Camera openCamera() {
        if (camera == null) {
            camera = Camera.open();
        }
        return camera;
    }

    public void releaseCamera() {
        if (camera != null) {
            camera.release();
            camera = null;
        }
    }

    public void startPreview(SurfaceHolder surfaceHolder) throws IOException {
        if (camera != null) {
            camera.setPreviewDisplay(surfaceHolder);
            camera.startPreview();
        }
    }

    public void stopPreview() {
        if (camera != null) {
            camera.stopPreview();
        }
    }

    public void takePhoto(Camera.PictureCallback pictureCallback) {
        if (camera != null) {
            camera.takePicture(null, null, pictureCallback);
        }
    }

    public void startRecording(Surface surface) throws IOException {
        if (mediaRecorder == null) {
            mediaRecorder = new MediaRecorder();
            camera.unlock();
            mediaRecorder.setCamera(camera);
            mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
            mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
            mediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
            mediaRecorder.setOutputFile(getOutputMediaFile().toString());
            mediaRecorder.setPreviewDisplay(surface);
            mediaRecorder.prepare();
            mediaRecorder.start();
        }
    }

    public void stopRecording() {
        if (mediaRecorder != null) {
            mediaRecorder.stop();
            mediaRecorder.reset();
            mediaRecorder.release();
            mediaRecorder = null;
        }
    }

    public boolean hasCamera(Context context) {
        if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
            return true;
        } else {
            return false;
        }
    }

    public boolean hasFrontCamera(Context context) {
        if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT)) {
            return true;
        } else {
            return false;
        }
    }

    private File getOutputMediaFile() {
        File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
                Environment.DIRECTORY_MOVIES), "MyCameraApp");
        if (!mediaStorageDir.exists()) {
            if (!mediaStorageDir.mkdirs()) {
                Log.d(TAG, "failed to create directory");
                return null;
            }
        }
        File mediaFile = new File(mediaStorageDir.getPath() + File.separator +
                "VID_" + System.currentTimeMillis() + ".mp4");
        return mediaFile;
    }
}

Haxe :

import lime.system.JNI;

class CameraActivity extends lime.app.Application {
    private var camera:Dynamic;

    public function new() {
        super();
    }

    override public function onCreate():Void {
        super.onCreate();

        // Call the native function to open the camera
        JNI.callStaticMethod("com.example.CameraManager", "openCamera", [], function(result:Dynamic) {
            camera = result;
        });

        // Create a new SurfaceView to display the camera preview
        var surfaceView = new lime.ui.SurfaceView();
        addChild(surfaceView);

        // Add a callback to start the camera preview when the SurfaceView is created
        surfaceView.onCreate = function(surfaceHolder:Dynamic) {
            JNI.callStaticMethod("com.example.CameraManager", "startPreview", [surfaceHolder], null);
        };

        // Create a button to take a photo
        var photoButton = new lime.ui.Button();
        photoButton.text = "Take Photo";
        photoButton.x = 100;
        photoButton.y = 100;
        photoButton.onClick = function() {
            // Call the native function to take a photo
            JNI.callStaticMethod("com.example.CameraManager", "takePhoto", [function(data:Dynamic) {
                // Convert the byte array to a Haxe ImageBuffer
                var imageBuffer = new ImageBuffer(data.width, data.height);
                imageBuffer.blit(data.data, 0, 0, data.width, data.height);

                // Create a new Texture from the ImageBuffer
                var texture = Texture.fromImageBuffer(imageBuffer);

                // Display the photo on the screen
                var bitmapSprite = new lime.graphics.Image(texture);
                var sprite = new lime.graphics.Sprite();
                sprite.addChild(bitmapSprite);
                addChild(sprite);
            }], null);
        };
        addChild(photoButton);

        // Create a button to start recording video
        var recordButton = new lime.ui.Button();
        recordButton.text = "Start Recording";
        recordButton.x = 200;
        recordButton.y = 100;
        recordButton.onClick = function() {
            // Call the native function to start recording
            JNI.callStaticMethod("com.example.CameraManager", "startRecording", [surfaceView.getSurface()], null);
        };
        addChild(recordButton);

        // Create a button to stop recording video
        var stopButton = new lime.ui.Button();
        stopButton.text = "Stop Recording";
        stopButton.x = 300;
        stopButton.y = 100;
        stopButton.onClick = function() {
            // Call the native function to stop recording
            JNI.callStaticMethod("com.example.CameraManager", "stopRecording", [], null);
        };
        addChild(stopButton);
    }

    override public function onDestroy():Void {
        super.onDestroy();

        // Call the native function to release the camera
        JNI.callStaticMethod("com.example.CameraManager", "releaseCamera", [], null);
    }
}

In the Haxe code, lime.system.JNI is used to call the Java methods to start and stop the camera preview, take photos, and start and stop recording video. The SurfaceView is used to display the camera preview, and buttons are used to trigger the photo and video recording actions. When a photo is taken, the image data is returned as a byte array, which is then converted to a Haxe ImageBuffer and displayed on the screen.

in XML file this permission :

<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />