폰갭(Phonegap) 3.0 외부플러그인 적용하기 - QR코드 인식기(BarcodeScanner)

by geusgod posted Aug 27, 2013
?

단축키

Prev이전 문서

Next다음 문서

ESC닫기

크게 작게 위로 아래로 댓글로 가기 인쇄

지금 글쓰는 게시판의 글쓰기 에디터가 말썽이네요~ 줄바꿈 했던게 모두 없어져 버리다니 -0-; 아무튼... 갈길이 바뻐서...


폰갭(Phonegap) 3.0 기본적인 예제를 끝내고 나니...

이제 확장을 하고 싶어 졌습니다.


그래서 각종 외부 플러그인을 적용하는 법을 알고자 합니다.


우선, 그 첫번째로 폽갭으로 QR코드 인식기를 만들고자 합니다.

현재 BarcodeScanner라고 불리우는 외부 플러그인이 있습니다.

이걸 적용해 보기로 했습니다. (다른건 못찾아서... --)


https://github.com/wildabeast/BarcodeScanner 들어가보니... 

첫 문구가 이거네요^^ Cross-platform BarcodeScanner for Cordova / PhoneGap.


그 다음 내용은...

----------------

Follows the Cordova Plugin spec, so that it works with Plugman.

This plugin leverages Cordova/PhoneGap's require/define functionality used for plugins.


Note: the Android source for this project includes an Android Library Project. plugman currently doesn't support Library Project refs, so its been prebuilt as a jar library. Any updates to the Library Project should be committed with an updated jar.

----------------

Plugman 이라는 용어가 보이고... 안드로이드 라이브러리 프로젝트를 지원하지 않는다고 하네요... 아무튼...


cmd 창에서 plugman 인스톨...

c:\npm install -g plugman

"C:\Users\사용자명\AppData\Roaming\npm\node_modules\" 폴더에 설치됨~


설치는 했지만... 아직 활용법을 몰라서... 우선 남겨두고...


phonegap 명령으로 바코드스캔 git 설치~
(cordova plugin add https://github.com/wildabeast/BarcodeScanner.git 명령어도 같은 작용을 하는듯...)

----------------

Windows PowerShell

Copyright (C) 2009 Microsoft Corporation. All rights reserved.


D:\임시보관\GitHub> cd c:\hello

C:\hello> phonegap local plugin add https://github.com/wildabeast/BarcodeScanner.git

[phonegap] adding the plugin: https://github.com/wildabeast/BarcodeScanner.git

[phonegap] successfully added the plugin

C:\hello>

----------------


설치하면 plugins 디렉토리에 com.phonegap.plugins.barcodescanner 폴더가 생성됨~


그다음... plugman 명령어를 활용하는데...

아래 명령어 실행전에... plugins\android.json 삭제.(불안하시면 다른곳에 옮기세요~)

plugman --plugins_dir plugins --plugin com.phonegap.plugins.barcodescanner --platform android --project platforms\android

좀전에 삭제된 파일과 assets/www 폴더에 barcodescanner.js 파일이 생성되어 있음.


아래 실행예제를 <script type="text/javascript" charset="utf-8"> </script> 태그에 넣어 줍니다~

1
2
3
4
5
6
7
8
9
10
11
12
13
var scanner = cordova.require("cordova/plugin/BarcodeScanner");
 
   scanner.scan(
      function (result) {
          alert("We got a barcode\n" +
                "Result: " + result.text + "\n" +
                "Format: " + result.format + "\n" +
                "Cancelled: " + result.cancelled);
      },
      function (error) {
          alert("Scanning failed: " + error);
      }
   );


에뮬을 실행하면... 당연히 function 에 scanner.scan() 들어가 있지 않으므로~ 바로 실행됩니다.



하지만... 에뮬에서는 사진을 찍을수 없으니.. ㅎㅎ (제폰에서는 잘 되네요~ 근데... 작은 QRCODE는 잘 인식이 안되네요 ㅠ.ㅠ)


Sketchbook5, 스케치북5

Sketchbook5, 스케치북5