android – NativeScript : custom camera view-ThrowExceptions

Exception or error:

I am working on an iOS and Android application with a custom camera view (that’s why I won’t use camera module

I need to have my own UI above the camera preview.

Can I do this with Nativescript ?

I could not find any module/plugin with this feature.
Is this hard to write my own module?

How to solve:

Use the surfaceview in layout.xml

                android:layout_height="260dp" />

use following code in activity class

SurfaceView surfaceView;
CameraSource cameraSource;

final TextRecognizer textRecognizer = new TextRecognizer.Builder(getApplicationContext()).build();
        cameraSource = new CameraSource.Builder(getApplicationContext(), textRecognizer)
        surfaceView.getHolder().addCallback(new SurfaceHolder.Callback() {
            public void surfaceCreated(SurfaceHolder surfaceHolder) {

                try {
                } catch (IOException e) {

            public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i1, int i2) {


            public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
        textRecognizer.setProcessor(new Detector.Processor<TextBlock>() {
            public void release() {



The Placeholder allows you to add any native widget to your application. To do that, you need to put a Placeholder somewhere in the UI hierarchy and then create and configure the native widget that you want to appear there. Finally, pass your native widget to the event arguments of the creatingView event.

NativeScript does not have a surface view and you need to use placeholder on top of camera plugin.

<Placeholder (creatingView)="creatingView($event)"></Placeholder>

public creatingView(args: any) {
var nativeView = new android.view.SurfaceView(;
args.view = nativeView;

Leave a Reply

Your email address will not be published. Required fields are marked *