返回码
Code | Message |
---|---|
1 | Success, get more information with vid |
1001 | Network Error, check network states |
1002 | Server Error |
1005 | VID Not Found |
2003 | NFC Tag Lost, if the nfc tag leaves the field or there is an I/O failure, try again |
2005 | NFC Auth Error with the wrong chip |
3001 | NFC not available on this device |
3002 | NFC is unable, Applications can request Settings UI allowing the user to toggle NFC using |
3005 | NFC Chip Copied |
4001 | NFC tag status detected as open |
4100 | NFC tag status detected as opened && copied |
9012 | VID No Permission, Please check your permission |
100003 | VID APP Signature Error |
100004 | VID APP Certification Error |
100006 | VID VerifyID Not Exist, Check your verify ID. |
快速开始
-
Sample Application. 在Android Studio中打开示例应用程序,并作为参考。
-
参考引用
repositories { flatDir { dirs 'libs' } } dependencies { implementation(name: 'vechain-verify-sdk', ext: 'aar') compileOnly files('sdkenc/classes.jar') implementation 'com.squareup.okhttp3:okhttp:3.14.8' implementation 'com.squareup.retrofit2:converter-gson:2.6.0' implementation 'com.squareup.retrofit2:retrofit:2.6.0' implementation 'com.squareup.retrofit2:adapter-rxjava2:2.6.0' implementation 'io.reactivex.rxjava2:rxandroid:2.1.1' implementation 'io.reactivex.rxjava2:rxjava:2.2.12' }
-
在Android清单中请求NFC和Internet访问
<uses-permission android:name="android.permission.NFC"/> <uses-permission android:name="android.permission.INTERNET"/>
-
注册SDK,在开始验证之前调用此方法
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); String verifyID = "verifyId is got from VeChain Toolchain Portal/Developer Center"; /* Register SDK, Call this method before you start to verify. */ VeChainNFCSDK.registerSDK(this, verifyID, new MySignAction()); }
public class MySignAction implements SignAction { /* MySignAction is the implementation of the interface SignAction. The purpose is to sign the incoming pair of challengeId and notifier. onSignResult (signInfo) to notify SDK to continue the registration process. */ @Override public void sign(Context context, String challengeId, SignNotifier signNotifier) { String certString = "Your certificate string"; String certKeyString = "Your certificate key"; String signature = CertUtils.getSignInfo(certString, certKeyString, challengeId); //More Detail about how to sign the challengeId and get signature, refers to Appendix A: FAQ - How to Sign ChallengeID signNotifier.onSignResult(signature, ""); } }
-
验证NFC标签的活动
@Override protected void onResume() { super.onResume(); VeChainNFCSDK.onResume(MainActivity.this, new VeChainNFCSDK.NfcSDKCallback() { @Override public void onVerifyStart() { //a callback to be invoked when the system finds a tag while the foreground activity is operating in reader mode. //You can refresh UI (like a loading dialog) in this callback. } @Override public void onResultReceived(VerifyResult verifyResult) { int code = verifyResult.getCode(); if (code == ResultCode.CODE_NETWORK_ERROR) { //Network error Toast.makeText(MainActivity.this, "Network Error", Toast.LENGTH_SHORT).show(); return; } if (code != ResultCode.OK) { //verify fail Toast.makeText(MainActivity.this, "Verify failed: error code is " + code, Toast.LENGTH_SHORT).show(); return; } //verify success String vid = verifyResult.getVid(); Toast.makeText(MainActivity.this, "VeChain verified Vid is " + vid, Toast.LENGTH_SHORT).show(); } }); } @Override protected void onPause() { super.onPause(); VeChainNFCSDK.onPause(); } @Override protected void onDestroy() { super.onDestroy(); VeChainNFCSDK.onDestroy(); }
API 参考
通过调用SDK工具类:com.vechain.prosdk.nfctools.VeChainNFCSDK,可以实现NFC sdk功能。
注册
/**
* Register SDK
* Call this method before verify the chip.
*
* @param context the context
* @param verifyId is got from VeChain Toolchain Portal/Developer Center;
*/
public static void registerSDK(@NonNull Context context, @NonNull String verifyId, @NonNull SignAction signAction)
启用NFC验证
/**
* enable nfc reader mode while this Activity is in the foreground.
* call this method every time the activity is resumed.
*
* @param activity the Activity that requests the adapter to be in reader mode
* @param callback the callback to be invoked when nfc verify result get
*/
public static void onResume(@NonNull Activity activity, @NonNull NfcSDKCallback callback)
禁用NFC验证
/**
* disable nfc reader mode before your Activity completes Activity#onPause.
*/
public static void onPause()
销毁
/**
* Cancel verify request while Activity in Activity#onDestroy.
*/
public static void onDestroy()
验证二维码类型vid
/**
* Check if QR-code is VID
*/
public static void verifyQRCode(String qrcode, @NonNull NfcSDKCallback callback) {
VidSDK.get().verifyVid(qrcode, callback);
}
NFCSDK回调
/**
* Provides callbacks to handle the lifecycle of nfc sdk
*/
public interface NfcSDKCallback {
/**
* The callback to be invoked when the system finds a tag while the foreground activity is
* operating in reader mode.
* You can refresh UI (like a loading dialog) in this callback.
*/
void onVerifyStart();
/**
* Provides this callback to handle the verifyResult
* The callback called on verify successful or failed.
* @param verifyResult result contains result code, vid.
*/
void onResultReceived(VerifyResult verifyResult);
}
版本
/**
* Get SDK Version
*/
public static String getVersion()
评论
0 条评论
请登录写评论。