Я новичок в nativescript.и извините за мой ломаный английский.Надеюсь, вы, ребята, можете помочь мне с этим.
У меня есть nativescript с приложением angular 2.В настоящее время я делаю маяк Bluetooth.я хочу иметь функцию камеры для моего приложения, о которой маяк будет уведомлять при каждом нажатии кнопки.
что я хочу, когда кнопка нажата.камера сделает снимок вместо того, чтобы вручную нажать на кнопку камеры.
вот мой код.
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>