Skip to content

Commit b32e4af

Browse files
Add Barcode Scanner
1 parent 8b5be62 commit b32e4af

File tree

6 files changed

+94
-0
lines changed

6 files changed

+94
-0
lines changed

src/app/app.imports.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ import { CreditCardScanPage } from '../pages/miscellaneous/credit-card-scan/cred
8888
import { RuntimePermissionsPage } from '../pages/miscellaneous/runtime-permissions/runtime-permissions';
8989
import { ChartsPage } from '../pages/miscellaneous/charts/charts';
9090
import { GetImagePage } from '../pages/miscellaneous/get-image/get-image';
91+
import { BarcodescannerPage } from '../pages/miscellaneous/barcodescanner/barcodescanner';
9192

9293
// Providers
9394
import { WeatherService } from '../pages/miscellaneous/weather/weather.service';
@@ -172,6 +173,7 @@ export const Pages = [
172173
GetImagePage,
173174
FlashCardComponent,
174175
FlashCardPage,
176+
BarcodescannerPage,
175177

176178
// Modals
177179
PopupModalsPage,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
$ sudo ionic plugin add phonegap-plugin-barcodescanner
2+
$ sudo ionic plugin add cordova-plugin-crosswalk-webview
3+
4+
$ sudo ionic build android
5+
$ adb install -r platforms/android/build/outputs/apk/android-armv7-debug.apk
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<ion-header>
2+
<ion-navbar>
3+
<ion-title>Barcode Scanner</ion-title>
4+
</ion-navbar>
5+
</ion-header>
6+
7+
8+
<ion-content padding>
9+
10+
<p>NOTE: THIS ONLY WORKS ON MOBILE!</p>
11+
12+
<div class="json">{{ barcodeData | json }}</div>
13+
14+
<div text-center>
15+
<button ion-button icon-left color="primary" (click)="scan()">
16+
<ion-icon name="qr-scanner"></ion-icon>
17+
Scan
18+
</button>
19+
</div>
20+
21+
</ion-content>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
page-barcodescanner {
2+
3+
.json {
4+
white-space: pre;
5+
}
6+
7+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { Component } from '@angular/core';
2+
import { NavController, AlertController } from 'ionic-angular';
3+
import { BarcodeScanner } from 'ionic-native';
4+
5+
@Component({
6+
selector: 'page-barcodescanner',
7+
templateUrl: 'barcodescanner.html'
8+
})
9+
export class BarcodescannerPage {
10+
11+
public barcodeData;
12+
13+
constructor(public navCtrl: NavController, public alertCtrl: AlertController) {}
14+
15+
ionViewDidLoad() {
16+
console.log('ionViewDidLoad BarcodescannerPage');
17+
}
18+
19+
scan() {
20+
21+
let opciones =
22+
{
23+
preferFrontCamera : false, // iOS and Android
24+
showFlipCameraButton : true, // iOS and Android
25+
showTorchButton : true, // iOS and Android
26+
torchOn: false, // Android, launch with the torch switched on (if available)
27+
prompt : "Place a barcode inside the scan area", // Android
28+
resultDisplayDuration: 500, // Android, display scanned text for X ms. 0 suppresses it entirely, default 1500
29+
formats : "QR_CODE,PDF_417", // default: all but PDF_417 and RSS_EXPANDED
30+
orientation : "portrait", // Android only (portrait|landscape), default unset so it rotates with the device
31+
disableAnimations : true, // iOS
32+
disableSuccessBeep: false // iOS
33+
};
34+
35+
BarcodeScanner.scan(opciones)
36+
.then((data) => {
37+
this.barcodeData = data;
38+
let alert = this.alertCtrl.create({
39+
title: 'Scan Results',
40+
subTitle: data.text,
41+
buttons: ['OK']
42+
});
43+
alert.present();
44+
}).catch( (err) => {
45+
let alert = this.alertCtrl.create({
46+
title: 'Attention!',
47+
subTitle: err,
48+
buttons: ['Close']
49+
});
50+
alert.present();
51+
});
52+
}
53+
54+
}

src/pages/miscellaneous/miscellaneous.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { ChatsPage } from './chat/chats';
66
import { WeatherPage } from './weather/weather';
77
import { CurrencyConverterPage } from './currency-converter/currency-converter';
88
import { FlashCardPage } from './flash-card/flash-card';
9+
import { BarcodescannerPage } from './barcodescanner/barcodescanner';
910
// import { ClockPage } from './clock/clock';
1011
import { CountdownOnePage } from './countdown/countdown';
1112
import { TestimonialsPage } from './testimonials/testimonials';
@@ -69,6 +70,10 @@ export class MiscellaneousListPage {
6970
title: 'Flash Card',
7071
page: FlashCardPage
7172
},
73+
{
74+
title: 'Barcode Scanner',
75+
page: BarcodescannerPage
76+
},
7277
// {
7378
// title: 'Weather',
7479
// page: WeatherPage

0 commit comments

Comments
 (0)