0

我正在尝试为 card.io 和 phonegap (crodova) 编写一个插件。我的问题是当我点击打开 card.io 扫描信用卡时,应用程序崩溃并出现以下错误:

11-16 14:19:52.990:E/SurfaceTextureClient(17199):queueBuffer:错误队列缓冲区到 SurfaceTexture,-9

11-16 14:19:55.580: A/libc(17199): 致命信号 11 (SIGSEGV) 在 0x00000010 (code=1)

我不是 java 专业人士,但我遵循了 phonegap 上的插件文档并查看了其他一些已经完成的文档。

下面是我的代码:

主班

package com.eliashajj.MyApp;

import org.apache.cordova.DroidGap;

import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.widget.TextView;
import com.elixir.vmart.R;

public class MyApp extends DroidGap {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.setIntegerProperty("splashscreen", R.drawable.splash);
        try {
            super.loadUrl("file:///android_asset/www/index.html", 10000);
        } catch (Exception e) {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("Error");
            builder.setMessage("Please make sure you have have and internet connection and try again.");
            builder.setPositiveButton("OK", null);
            AlertDialog dialog = builder.show();

            TextView messageView = (TextView) dialog
                    .findViewById(android.R.id.message);
            messageView.setGravity(Gravity.CENTER);
        }
    }
}

这是我的 Card.IO 处理程序

package com.eliashajj.MyApp;

import io.card.payment.CardIOActivity;
import io.card.payment.CreditCard;

import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import android.content.Intent;
import android.util.Log;


public class Cardio extends Plugin{

    private static final String MY_CARDIO_APP_TOKEN = "MY APP TOKEN";
    private static final String SCAN = "scan";
    private static final String CC_VARIABLE = "cc_number";
    private static final String CC_MONTH_VARIABLE = "cc_month";
    private static final String CC_YEAR_VARIABLE = "cc_year";
    private static final String CC_CVV_VARIABLE = "cc_cvv";
    private static String CC_NUMBER;
    private static int EXPIRY_MONTH;
    private static int EXPIRY_YEAR;
    private static int CVV_NUMBER;


    public String callback;
    public static final int REQUEST_CODE = 0x0ba7c0de;

    /*
     * Constructor
     */
    public Cardio(){

    }

    /*
     * Executes the request and returns PluginResult.
     *
     * @param action        The action to execute.
     * @param args          JSONArry of arguments for the plugin.
     * @param callbackId    The callback id used when calling back into JavaScript.
     * @return              A PluginResult object with a status and message.
     */
    public PluginResult execute(String action, JSONArray args, String callbackId) {
        this.callback=callbackId;

        //Context cc = this.cordova.getActivity().getApplicationContext();
        if(action.equals(SCAN)){
            scan();
        }
        PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT);
        r.setKeepCallback(true);
        return r;
    }

    public void scan() {
        // This method is set up as an onClick handler in the layout xml
        // e.g. android:onClick="onScanPress"
        Context cc = this.cordova.getActivity().getApplicationContext();

        Intent scanIntent = new Intent(cc, CardIOActivity.class);

        // required for authentication with card.io
        scanIntent.putExtra(CardIOActivity.EXTRA_APP_TOKEN, MY_CARDIO_APP_TOKEN);

        // customize these values to suit your needs.
        scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_EXPIRY, true); // default: true
        scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_CVV, true); // default: false
        scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_ZIP, false); // default: false

        // hides the manual entry button
        // if set, developers should provide their own manual entry mechanism in the app
        scanIntent.putExtra(CardIOActivity.EXTRA_SUPPRESS_MANUAL_ENTRY, false); // default: false

        Log.d("SCANNING TAG: ", "1");
        // MY_SCAN_REQUEST_CODE is arbitrary and is only used within this activity.
        this.cordova.startActivityForResult((Plugin) this, scanIntent, REQUEST_CODE);
        Log.d("SCANNING TAG: ", "2");
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        Log.d("SCANNING TAG: ", "3");
        super.onActivityResult(requestCode, resultCode, data);
        Log.d("SCANNING TAG: ", "4");

        Log.d("Request Code: ",""+requestCode);
        Log.d("Request Code 2: ",""+REQUEST_CODE);

        if (requestCode == REQUEST_CODE) {
            Log.d("SCANNING TAG: ", "Data"+data);
            if (data != null && data.hasExtra(CardIOActivity.EXTRA_SCAN_RESULT)) {
                JSONObject obj = new JSONObject();
                CreditCard scanResult = data.getParcelableExtra(CardIOActivity.EXTRA_SCAN_RESULT);

                // Never log a raw card number. Avoid displaying it, but if necessary use getFormattedCardNumber()
                CC_NUMBER = scanResult.getRedactedCardNumber();
                // CC Expiry Month
                EXPIRY_MONTH = scanResult.expiryMonth;
                // CC Expiry Year
                EXPIRY_YEAR = scanResult.expiryYear;
                // CC CVV Number
                CVV_NUMBER = scanResult.cvv.length();

                try{
                    obj.put(CC_VARIABLE, CC_NUMBER);
                    obj.put(CC_MONTH_VARIABLE, EXPIRY_MONTH);
                    obj.put(CC_YEAR_VARIABLE, EXPIRY_YEAR);
                    obj.put(CC_CVV_VARIABLE, CVV_NUMBER);
                }
                catch(JSONException e){

                }
                this.success(new PluginResult(PluginResult.Status.OK, obj), this.callback);
            }
        }
        else {
            // Scanning was canceled
        }
    }

    protected void onResume() {
        super.onResume(true);

    }
}

这是我的 Cordova 插件 javascript

var Cardio = function() {
};


//-------------------------------------------------------------------
Cardio.prototype.scan = function(successCallback, errorCallback) {
    if (errorCallback == null) { errorCallback = function() {}}

    if (typeof errorCallback != "function")  {
        console.log("Cardio.scan failure: failure parameter not a function");
        return
    }

    if (typeof successCallback != "function") {
        console.log("Cardio.scan failure: success callback parameter must be a function");
        return
    }

    cordova.exec(successCallback, errorCallback, 'Cardio', 'scan', []);
};

//-------------------------------------------------------------------

if(!window.plugins) {
    window.plugins = {};
}
if (!window.plugins.cardio) {
    window.plugins.cardio = new Cardio();
}

任何帮助,将不胜感激。先感谢您。

4

1 回答 1

0

libc SIGSEGV 是来自本机层 (libc) 的段错误。其中一些确实在 3.0.2 版本中得到修复,因此请确保您拥有最新版本的 SDK。

否则,如果不查看本机故障转储,就很难确切知道问题出在哪里。这些有时隐藏在 DDMS logcat 视图中,因为它们是由 Android 而不是托管应用程序生成的,因此您需要确保删除任何 logcat 过滤才能看到它。

于 2012-11-16T16:50:01.580 回答