Android Add business card scanning function Instance code _android

Source: Internet
Author: User
Tags auth stub uuid

To achieve the Android phone by scanning business cards, get business card information, you can use the pulse-provided Third-party SDK, that is, the Maketion Scancard SDK, Pulse-seeking cloud business card recognition services. Their official website is http://www.maketion.com/.

I. Overview

Maketion SCANCARDSDK (hereinafter referred to as the SDK) is provided to the third Party partner access Pulse can seek cloud business card identification services, partners need to apply for key and secure before they can use.

The SDK cannot be run on its own, and it needs to be embedded in the Android project when used.

The SDK supports Android2.1 version and the above version of Project.

The process of pulse-seeking identification service is: Authentication-> open the SDK Camera page-> take the business card-> confirm upload success-> get the data.

Second, the installation process

1. Add "Scancardsdk.jar" to the "lib/" Directory of the Project

2. Add "libappmain.so" to the "lib/armeabi/" Directory of the Project

3. Add the following permissions in the project's "Androidmanifest.xml" file:

<uses-feature android:name= "Android.hardware.camera"/>
<uses-feature android:name= " Android.hardware.camera.autofocus "/>
<uses-permission android:name=" Android.permission.CAMERA "/>"
<uses-permission android:name= "Android.permission.INTERNET"/>
<uses-permission android:name= " Android.permission.ACCESS_FINE_LOCATION "/>
<uses-permission android:name=" android.permission.ACCESS_ Network_state "/>

4. Continue to add the registration information in the "Androidmanifest.xml" <application> Tags:

<activity android:name= "Cn.maketion.uploadSdk.MkxActivityCamera"/>

Third, the camera page

Cn.maketion.uploadSdk.MkxActivityCamera is an activity-based camera page provided by the SDK for capturing business cards and automatically submitting cloud recognition. can use

The following methods are invoked:

Intent Intent = new Intent (this, mkxactivitycamera.class);

Four, the SDK function

The Cn.maketion.uploadSdk.MkxServer class is a single example. Get an instance of this class first, and then call all the functional functions of this class through an instance

1. Get Mkxserver class instance

public static Mkxserver Getserver (Application app)

This function allows you to get an instance of Mkxserver.

2. Verification function

Public-void Auth (string key, String secure, String uid, mkxbackinit back) public
Boolean Isauth ()

The validation features include three functions: Auth () Commit validation, Isauth () to determine the validation status, and Clearauth () to clear the validation status.

Parameter key: From the pulse can be found in business Card recognition service application for access;

Parameters secure: From the pulse can be found in Business Card Identification Service application for access;

Parameter back: Callback interface

3. Get Business Card information

public void Getdatawithuuid (string[] UUIDs, final mkxbackcards back)

There are two ways to get business card information: Get business card information through the keyword UUID of the business card, and get all the business card information after a point in time.

Parameter UUIDs: An array of strings, each of which is a business card's UUID;

Parameter time: the "Seconds" (number if this parameter is 0 to obtain all business card information, does not contain the deleted business card and the unrecognized business card) which begins after January 1, 1970;

Parameter back: Callback interface

4. Monitor Upload Events

public void Setuploadlistener (Mkxbackupload back)

Monitor the upload event by setting the callback function.

Parameter back: Callback interface, see chapter Fifth, section 4th

5, upload business card pictures

public void Uploadimage (String uuid)

Upload failure occurs when listening for upload events, which can be uploaded via this function.

Parameter uuid: The UUID of the business card to upload

6, set SDcard picture cache path

public void Setsdcardpath (String sdcardpath)

After you set the SDcard path, the picture that is generated by taking the business card is kept under this path.

The cache path on the parameter Sdcardpath:sdcard, for example: Setsdcardpath ("Imagecache");

The captured business card will be saved to the "\sdcard\imagecache\" path.

7. Get the original card

public void Getcardimage (String uuid, mkxbackpicture back)

Obtain the original card by using the UUID of the business card. This function first checks whether the picture cache path has a corresponding original image (business card UUID is the name of the business card under the cached path), and if it exists, it returns the file name directly, and then returns it if it does not exist.

Parameter uuid: The UUID of the business card to get the original artwork

Parameter back: Callback interface,

Five, callback interface

1. Error message

Public interface Mkxerrorcode {
int code_success = 0;
int code_fail_result = 1; Result error
int code_fail_decode = 2;//JSON parsing error
int code_fail_null = 3;//network error, including 500 or 502 error
int Code_fail_timeo UT = 4; Connection Timeout
int code_fail_network = 5;//network error, no network or network not available
int code_fail_repeat = 6;/interface repeats calls, and calls
int CO for two times without waiting for interface return De_fail_unknow = 9; Unknown error

All network access function calls return the status Code code, which indicates that the interface call was successful when the code value was code_success, otherwise the interface call failed.

2. Verify Callback interface

Public interface Mkxbackauth extends Mkxerrorcode {
void onback (int code, String errinfo);

Parameter code: Network call State, if the code value is code_success to express validation pass;

Parameter errinfo: Returns error reference information when a network call fails.

3, get the card information callback interface

public class Mkxcard {public
string carduuid;//Business card UUID public 
string name;//Name public 
string duty;//Header Title Public 
string Mobile1//Mobile phone 1 public 
string Mobile2//Mobile 2 public 
string Email;//mailbox Public 
string Tel1; Telephone 1 public 
string TEL2//Telephone 2 public 
string Fax;//Fax public string CNAME// 
company name 
public string address;  Address public 
string website;//URL public 
string logo;//avatar public 
long createtime;//Create Time 
public Long UpdateTime;  Update Time public 
String fields//Completed field, "100" is complete public
int Audit//is unrecognized, greater than 1 is unable to recognize public 
int flag; ID, 0 is valid, 1 is deleted
} public 
Interface Mkxbackcards extends Mkxerrorcode {
void onback (int code, String Erri NFO, mkxcard[] cards);

Parameter code: Network call State;

Parameter errinfo: Returns the error reference information when the network call fails;

Parameter cards: An array of business card information returned.

4. Upload Listener Callback interface

Public interface Mkxbackupload extends Mkxerrorcode {
int status_start = 0;
int status_sucess = 1;
int status_error = 2;
void Onback (int code, string errinfo, string uuid, int status);
}

Parameter code: Network call State;

Parameter errinfo: Returns the error reference information when the network call fails;

Parameter UUID: currently uploading the business card uuid;

Parameter Status:status_start to start uploading, Status_sucess said upload success, Status_error said upload failed.

5, get the original card callback interface

Public interface Mkxbackpicture {
void Onback (File picture);
}

Parameter Picture: Business Card Original file, if the picture is null to get the original image failed;

Layered structure of packages


Next look, I made a small demo, test scan business card function

Project Content

Adding permissions and activity to the Mainfest.xml file

<uses-feature android:name= "Android.hardware.camera"/>
<uses-feature android:name= " Android.hardware.camera.autofocus "/>
<uses-permission android:name=" Android.permission.CAMERA "/>"
<uses-permission android:name= "Android.permission.INTERNET"/>
<uses-permission android:name= " Android.permission.ACCESS_FINE_LOCATION "/>
<uses-permission android:name=" android.permission.ACCESS_ Network_state "/>
<uses-permission android:name=" Android.permission.WRITE_EXTERNAL_STORAGE "/>" 
<activity android:name= "Cn.maketion.uploadSdk.MkxActivityCamera"/>
<activity android:name= " Com.example.maketiontest.CardDetailActivity "/>
<activity android:name=" Com.example.maketiontest.MaketionActivity "/>

The main maketionactivity are two methods Takepic () methods and Authenticateaccount () methods.

First, in the OnCreate method, we get the Mkxserver instance and determine if it has been validated

@Override
protected void onCreate (Bundle arg0) {
//TODO auto-generated method Stub
super.oncreate (ARG0); C4/>server = Mkxserver.getserver (Getapplication ());
Isinit = Server.isauth ();
if (isinit) {
takepic ();
} else {
authenticateaccount ();
}
}

If it has been validated, take a picture, and if it is not validated, verify

Authenticateaccount method

/**
* Verification Account */
private void Authenticateaccount () {
if (!isinit) {
Server.auth (KEY, SECRET, PUID, New Mkxbackauth () {
@Override public
void Onback (int code, String errinfo) {
if (code = = Mkxerrorcode . code_success) {
isinit = Server.isauth ();
if (isinit) {
log.i (TAG, "verify success!");
Takepic ();
} else {
log.i (TAG, "validation failed!");
Finish ();
}
else {
log.i (TAG, errinfo);
Finish ();}}}
);
}

Photo function

/** * Photo Operation * * private void Takepic () {if (isinit) {Server.setuploadlistener (new Mkxbackupload () {@Override public void Onback (int code, string errinfo, string uuid, int status) {log.i (TAG, uuid); muuid = uuid; switch (status) {case status
_error://upload error if (uploadtimes <= 5) {//due to upload and photo upload are calling the unified upload function, so you need to limit the number of retransmission, to avoid uploading images when the infinite recursion uploadtimes++;
Server.uploadimage (UUID);//re-upload} else {//upload the number of times to reach the upper limit, no longer upload, save can not upload the image of the UUID uploadtimes = 0; Uploadfails.add (UUID);
LOG.I (TAG, "Upload failure, wait for the network unobstructed and then upload again");
} break;
Case status_start://began to upload break; Case status_sucess://Upload Success Server.getdatawithuuid (new string[] {UUID}, new Mkxbackcards () {@Override public void Onback (int code, String cards, mkxcard[] arg2) {//TODO auto-generated method stub if (code = = mkxerrorcode.code_success) {if (isinit) {//Up
Success is to enter the business Card page Intent Intent = new Intent (maketionactivity.this, Carddetailactivity.class);
Intent.putextra ("uuid", muuid);
StartActivity (Intent); else {log.i (TAG, "not verified account");
}
}
}
});
LOG.I (TAG, "upload success");
Break
}
}
});
Intent Intent = new Intent (this, mkxactivitycamera.class);
StartActivity (Intent); else {log.i (TAG, "have not verified the account, please verify the account to obtain data"); Finish ();}

Carddetailactivity

protected void OnCreate (Bundle savedinstancestate) {
//TODO auto-generated method stub
super.oncreate ( Savedinstancestate);
LOG.I (TAG, "carddetailactivity------>oncreate");
Setcontentview (r.layout.card_detail_activity);
Server = Mkxserver.getserver (Getapplication ());
if (getintent ()!= null
&&! Textutils.isempty (Getintent (). Getstringextra ("UUID")) {
String uuid = Getintent (). Getstringextra ("UUID"). ToString ();
Get single card information
server.getdatawithuuid (new string[] {UUID}, new Mkxbackcards () {
@Override public
Void Onback (int code, String info, mkxcard[] cards) {
if (code = = mkxerrorcode.code_success) {
log.i (TAG, "" + Cards . length);
if (cards.length!= 0) {
Setview (cards);
}}}
);
else {
log.i (TAG, "no UUID acquired") ;
}
}

The thing that makes me wonder is why when you get a single card information, the callback method Onback, the parameter is mkxcard[] Cards

Why is an array of objects = =. Can not see the source of the SDK, there is no way ~

After running, not every photo can get information, overall, still not very good, it is recommended to use two-dimensional code will be better, or with NFC.

The results are unsatisfactory ~ ~


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.