卡io不扫描android中的信用卡 [英] card io not scanning credit card in android

查看:83
本文介绍了卡io不扫描android中的信用卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的应用程序中实现Card.io,我遵循了

I am trying to implement Card.io in my app, I followed the instructions on

这是我的清单代码:

 <uses-sdk android:minSdkVersion="8" />

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />

<uses-feature
    android:name="android.hardware.camera"
    android:required="false" />
<uses-feature
    android:name="android.hardware.camera.autofocus"
    android:required="false" />

<application
    android:label="card.io example"
    android:theme="@style/MyTheme" >
    <activity
        android:name="MyScanActivity"
        android:label="card.io example" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="io.card.payment.CardIOActivity"
        android:configChanges="keyboardHidden|orientation"
        android:hardwareAccelerated="true" />
    <activity
        android:name="io.card.payment.DataEntryActivity"
        android:screenOrientation="portrait" />
</application>

这是我的Java代码

public class MyScanActivity extends Activity {
final String TAG = getClass().getName();

private Button scanButton;
private TextView resultTextView;

private int MY_SCAN_REQUEST_CODE = 100; 
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    resultTextView = (TextView) findViewById(R.id.resultTextView);
    scanButton = (Button) findViewById(R.id.scanButton);

}

@Override
protected void onResume() {
    super.onResume();

    if (CardIOActivity.canReadCardWithCamera()) {
        scanButton.setText("Scan a credit card with card.io");
    } else {
        scanButton.setText("Enter credit card information");
    }
}

public void onScanPress(View v) {

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

    scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_EXPIRY, true); 
    scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_CVV, false);
    scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_POSTAL_CODE, false); 

    scanIntent.putExtra(CardIOActivity.EXTRA_SUPPRESS_MANUAL_ENTRY, false); 

    scanIntent.putExtra(CardIOActivity.EXTRA_KEEP_APPLICATION_THEME, false); 

    startActivityForResult(scanIntent, MY_SCAN_REQUEST_CODE);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    String resultStr;
    if (data != null && data.hasExtra(CardIOActivity.EXTRA_SCAN_RESULT)) {
        CreditCard scanResult = data.getParcelableExtra(CardIOActivity.EXTRA_SCAN_RESULT);

        resultStr = "Card Number: " + scanResult.getRedactedCardNumber() + "\n";

        if (scanResult.isExpiryValid()) {
            resultStr += "Expiration Date: " + scanResult.expiryMonth + "/" + scanResult.expiryYear + "\n";
        }

        if (scanResult.cvv != null) {

            resultStr += "CVV has " + scanResult.cvv.length() + " digits.\n";
        }

        if (scanResult.postalCode != null) {
            resultStr += "Postal Code: " + scanResult.postalCode + "\n";
        }
    } else {
        resultStr = "Scan was canceled.";
    }
    resultTextView.setText(resultStr);

}

}

我从未使用过card.io,也不知道出了什么问题。如何使用Card.io扫描签证或其他信用卡。
如果有人知道解决方案,请帮助我。

I have never used card.io and I don't know what is wrong. How can I to scan my visa or some other card with Card.io. If anyone knows solution please help me.

推荐答案


我见过你还没有将点击侦听器添加到

I have seen you haven't add a click listener to



scanButton.setOnClickListener();

测试此示例

public class CardActivity extends Activity {

    private int MY_SCAN_REQUEST_CODE = 100;

    Button scanButton;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.card_io_layout);

        scanButton = (Button)findViewById(R.id.button);
        scanButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onScan();
            }
        });
    }

    private void onScan() {
    if (CardIOActivity.canReadCardWithCamera()) {
        Intent scanIntent = new Intent(this, CardIOActivity.class);
        scanIntent.putExtra(CardIOActivity.EXTRA_APP_TOKEN,"999551db82b04e36b0664ab8217e0624");

        scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_EXPIRY,true);
        scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_CVV,false);
        scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_POSTAL_CODE,false);
        scanIntent.putExtra(CardIOActivity.EXTRA_SUPPRESS_MANUAL_ENTRY, false);

        startActivityForResult(scanIntent,MY_SCAN_REQUEST_CODE);
    }
    else{
        //Toast camera not supported So enter card manually
    }

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data){
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == MY_SCAN_REQUEST_CODE) {
            String resultDisplayString;
            if (data != null && data.hasExtra(CardIOActivity.EXTRA_SCAN_RESULT)) {
                CreditCard scanResult = data.getParcelableExtra(CardIOActivity.EXTRA_SCAN_RESULT);
                ((EditText)findViewById(R.id.textView)).setText(scanResult.getRedactedCardNumber());
            }
        }
    }
    @Override
    protected void onResume() {
        super.onResume();
        if (CardIOActivity.canReadCardWithCamera(this)) {
            scanButton.setText("Scan a credit card with card.io");
        }
        else {
            scanButton.setText("Enter credit card information");
        }
    }
}

这篇关于卡io不扫描android中的信用卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆