Phonegap barcodescanner encode function stops app

假如想象 提交于 2020-01-04 09:17:02

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/26333436/phonegap-barcodescanner-encode-function-stops-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!