Skip to content

Commit 8b34052

Browse files
authored
Merge pull request yannbf#18 from miguelcarrascoq/barcodescanner
Adds Barcode Scanner feature to miscellaneous
2 parents 8b5be62 + dc22e6b commit 8b34052

File tree

6 files changed

+113
-0
lines changed

6 files changed

+113
-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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Barcode Scanner
2+
You can check more info on the docs: https://github.com/phonegap/phonegap-plugin-barcodescanner
3+
4+
In order to use this feature, you have to install the plugin:
5+
```sh
6+
$ ionic plugin add phonegap-plugin-barcodescanner --save --variable CAMERA_USAGE_DESCRIPTION="To scan barcodes"
7+
```
8+
9+
Important note: Since iOS 10 it's mandatory to add a `NSCameraUsageDescription` in the info.plist.
10+
11+
`NSCameraUsageDescription` describes the reason that the app accesses the user’s camera. When the system prompts the user to allow access, this string is displayed as part of the dialog box.
12+
13+
This entry is passed on the `--variable` flag on plugin install.
14+
15+
16+
In case you want to support low end/old devices, make sure to install crosswalk:
17+
```sh
18+
$ ionic plugin add cordova-plugin-crosswalk-webview
19+
```
20+
21+
You can either try it out on a device or try it using an emulator:
22+
```sh
23+
$ ionic build android
24+
$ adb install -r platforms/android/build/outputs/apk/android-armv7-debug.apk
25+
```
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: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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 options =
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(options)
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+
}

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';
@@ -25,6 +26,10 @@ export class MiscellaneousListPage {
2526

2627
constructor(public navCtrl: NavController, public menu: MenuController) {
2728
this.items = [
29+
{
30+
title: 'Barcode Scanner',
31+
page: BarcodescannerPage
32+
},
2833
{
2934
title: 'Blog Post',
3035
page: BlogPostPage

0 commit comments

Comments
 (0)