2012-11-16 36 views
0

我正在嘗試爲card.io和phonegap(crodova)編寫一個插件。我的問題是,當我點擊打開card.io掃描信用卡時,應用程序崩潰,出現以下錯誤:card.io Android Phonegap集成

11-16 14:19:52.990:E/SurfaceTextureClient(17199):queueBuffer:錯誤排隊緩衝區到表面紋理,-9

11-16 14:19:55.580:A/libc的(17199):致命信號在0x00000010(代碼= 1)

11(SIGSEGV)我不是在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); 

    } 
} 

這裏是我的科爾多瓦插件的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(); 
} 

任何幫助,將不勝感激。 預先感謝您。

+0

您在Java代碼中有很多日誌,它們在adb logcat中顯示在哪裏? –

回答

0

libc SIGSEGV是本地層(libc)的段錯誤。其中一些在3.0.2版本中得到修復,因此請確保您已獲得最新版本的SDK。

否則,很難確切地知道問題出在沒有看到本地崩潰轉儲的情況下。這些有時隱藏在DDMS logcat視圖中,因爲它們是由Android生成的,而不是託管應用程序生成的,所以您需要確保刪除任何logcat過濾器才能看到它。