card.io Android Phonegap Integration

时间:2012-11-16 12:37:07

标签: cordova phonegap-plugins card.io

我正在尝试为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(代码= 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();
}

任何帮助将不胜感激。 提前谢谢。

1 个答案:

答案 0 :(得分:0)

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

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