user4067088
user4067088

Reputation: 23

Phonegap barcodescanner encode function stops app

I am using barcodescanner.js plugin in my phonegap app and everything is working great for the following code.

var scanner = cordova.require("cordova/plugin/BarcodeScanner");
  scanner.encode(scanner.Encode.TEXT_TYPE, 123456789, function(success) {
             alert("encode success: " + success);
           }, function(fail) {
             alert("encoding failed: " + fail);
           });

but having an issue when encode finishes app stops. Have anyone got any example code of creating an additional function to invoke the success callback. My requirement is to display barcode/QR code in the screen from saved phone text data.

Upvotes: 2

Views: 2203

Answers (1)

Daniel Cheung
Daniel Cheung

Reputation: 4819

I used my whole day searching for this. Found it on here: https://github.com/wildabeast/BarcodeScanner/issues/71

You need to search for menu/encode.xml in your file explorer from your project's root and replace it with: http://zxing.googlecode.com/svn/trunk/android/res/menu/encode.xml

If the link is ever unavailable, here is the code:

<?xml version="1.0" encoding="UTF-8"?>
<!--
 Copyright (C) 2012 ZXing authors

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 -->
<menu xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:id="@+id/menu_share"
        android:title="@string/menu_share"
        android:icon="@android:drawable/ic_menu_share"
        android:orderInCategory="1"
        android:showAsAction="withText|ifRoom"/>
  <item android:id="@+id/menu_encode"
        android:title="@string/menu_encode_vcard"
        android:icon="@android:drawable/ic_menu_sort_alphabetically"
        android:orderInCategory="2"
        android:showAsAction="withText|ifRoom"/>
</menu>

Phonegap really needs a better community page and documentation.

Upvotes: 4

Related Questions