0

i am new to nativescript. and sorry for my broken English. hope you guys can help me with this.

i have a nativescript with angular 2 application. i am currently doing the Bluetooth beacon. i want to have the camera feature for my application which beacon will notify everytime the button is pressed.

what i want is, when button is pressed. camera will take picture instead of user manual click on camera button.

here is my code.

 bluetooth.startNotifying({
            peripheralUUID: "FF:FF:90:01:B1:EF",
            serviceUUID: "ffe0",
            characteristicUUID: "ffe1",
            onNotify: function (result) {
                try {
                    var data = new Uint8Array(result.value);
                    console.log('notify: ' + JSON.stringify(data[0]));
                    /*  camera.takePicture()*/
                    if (data[0] = 1) {
                        camera.takePicture()
                            .then(function (imageAsset) {
                            console.log("Result is an image asset instance");
                            var image = new imageModule.Image();
                            image.src = imageAsset;
                        }).catch(function (err) {
                            console.log("Error -> " + err.message);
                        });
                    }
                }
                catch (e) {
                    alert('notify value not readable: ' + e.message);
                }
            }
        }).then(function () {
            console.log("subscribed for notifications");
        });
<ActionBar title="Camera" >

</ActionBar>
<ScrollView orientation="horizontal">
<GridLayout rows="auto, *, auto, auto,auto">

        <StackLayout row="0" orientation="vertical" padding="10">
            <StackLayout orientation="horizontal" padding="10">
                <Label text="saveToGallery"></Label>
                <Switch [(ngModel)]="saveToGallery"></Switch>
            </StackLayout>
            <StackLayout orientation="horizontal" padding="10">
                <Label text="keepAspectRatio"></Label>
                <Switch [(ngModel)]="keepAspectRatio"></Switch>
            </StackLayout>
            <StackLayout orientation="horizontal" padding="10">
                <Label text="width"></Label>
                <TextField hint="Enter width" keyboardType="number" [(ngModel)]="width" class="input"></TextField>
                <Label text="height"></Label>
                <TextField hint="Enter height" keyboardType="number" [(ngModel)]="height" class="input"></TextField>
            </StackLayout>
        </StackLayout>
    
        <Image row="1" [src]="cameraImage" stretch="aspectFit" margin="10"></Image>
        <TextView row="2" [(ngModel)]="labelText" editable="false"></TextView>>
        <Button row="3" text="Take Picture" (tap)='onTakePictureTap($event)' padding="10"></Button>
        <Button row="4" text="Done" (tap)="onDoneTakePicture()"  ></Button>
    </GridLayout> 
</ScrollView>
Norain
  • 19
  • 4
  • code looks fine to me. What is the problem you are facing? – Narendra Nov 16 '18 at 02:28
  • ok. currently this one works fine. but the thing is. i have to click on camera button to take a picture. what i want is, camera take a picture without click on camera button but take picture everytime (data[0] = 1) which is the beacon is pressed. – Norain Nov 16 '18 at 02:43
  • for which platform do you want? For android, this might be a useful thread, you need to convert code https://stackoverflow.com/questions/9752730/take-a-photo-automatically-without-user-interaction – Narendra Nov 16 '18 at 03:16
  • for android. i know that .then(function (imageAsset) will execute when user click on save button at the camera. can i know how do i know when the camera button is click? – Norain Nov 16 '18 at 03:42
  • you can use https://www.npmjs.com/package/nativescript-open-app plugin if you want to open the camera from your app – Narendra Nov 16 '18 at 04:42
  • hi @NarendraMongiya ,... this is not what i want. i already have camera in my app using nativescript-camera plugin. what i want to know is how can i take picture without click on camera button but use the beacon pressed button. :) – Norain Nov 16 '18 at 06:19

0 Answers0