The usage of the Android SDK V1.0 is described in the following code:

Source: Internet
Author: User

The usage of the Android SDK V1.0 is described in the following code:
The Android SDK of GPRS inter is designed to develop and use Jiabo printers on the Android platform faster and more efficiently. If you encounter problems in using the SDK or find bugs, please feel free to contact me, send email to MrAladin@163.com1. Download the GPRS intersdk

? Current = down or you can download the SDK.

1. Import maid. jar to the Project

In eclipse, copy maid. jar to the libs folder of the project ,.

2. Establish communications with printers 1. Get the device object
GpDevice mDevice = new GpDevice();
2. register the receive data callback function (this interface is used to receive data)
mDevice.registerCallback(this);
3. Enable Bluetooth, USB, and network port Bluetooth Communication:

A. To obtain the Bluetooth operation permission, add the following code to AndroidManifest. xml:

<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /><uses-permission android:name="android.permission.BLUETOOTH" />  

B. Call Bluetooth to open the API

mDevice.openBluetoothPort(Context context,String addr)

Context is the context, and addr is the Bluetooth address. For example, if the Bluetooth address is "98: D3: 31: 40: 27: D7 ",

mDevice.openBluetoothPort(MainActivity.this,"98:D3:31:40:27:D7");
USB communication

A. To obtain the USB operation permission, add the following code to AndroidManifest. xml:

<uses-feature android:name="android.hardware.usb.host" />

B. register the USB device to insert and unplug the broadcast. In AndroidManifest. xml, add the following code:

 <intent-filter>     <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" /> </intent-filter> <intent-filter>      <action android:name="android.hardware.usb.action.USB_DEVICE_DETACHED" /> </intent-filter> <meta-data      android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"      android:resource="@xml/device_filter" /> <meta-data      android:name="android.hardware.usb.action.USB_DEVICE_DETACHED"      android:resource="@xml/device_filter" />    

C. device_filter.xml is a filter file for the USB device, which stores the PID and VID of the USB device. Only the USB Plug-in of the matching device can generate a USB Plug-in or pull-out broadcast, device_filter.xml must be placed in the res/xml folder. The file format is as follows. For example, the vid of the Gp2120TL label printer is 26728 PID 1280.

<?xml version="1.0" encoding="utf-8"?><resources>       <usb-device vendor-id="26728" product-id="1280" /></resources>

D. The old Android SDK does not support USB host. The minimum SDK version is 12. Therefore, you must add

android:minSdkVersion="12"

E. Call the USB port to open the API

mDevice.openBluetoothPort(MainActivity.this);
Network port communication

A. To obtain Network Operation permissions, add the following code to AndroidManifest. xml:

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

B. Call the network port API

For example, the initial IP address of the Jiabo network printer is 192.168.123.100, and the print port is 9100.

mDevice.openEthernetPort(“192.168.123.100”, 9100)
4. Disable Bluetooth, USB, and Network Ports

Call the disable port API

mDevice.closePort();
5. Send data

Send data now API

mDevice.sendDataImmediately(Vector<Byte> data)

Place the sent data in the sending Buffer

mDevice.sendData(Vector<Byte> data)
3. Edit TSC and ESC commands

Jiabo printers are compatible with two industry command standards. 5890 XIII, 58130IVC, and other ticket printers are compatible with ESC/POS instruction sets;

2120 TB, 2120TL, and other series label printers are compatible with the TSC Instruction Set;

2120TF is compatible with ESC and TSC at the same time. To switch the mode, you need to switch the dial.

1. the TSC command call template is as follows. The JavaDoc file in the GPRS inter SDK contains the call description of the TSCCommand API.
TscCommand tsc = new TscCommand (60, 30, 0); // set the label size width, height, and gap tsc. addReference (0, 0); // sets the origin coordinate tsc. addSpeed (SPEED. SPEED1DIV5); // sets the printing speed tsc. addDensity (DENSITY. DNESITY0); // sets the print concentration tsc. addDirection (DIRECTION. BACKWARD); // set the printing direction to tsc. addCls (); // clear the print buffer tsc. addSound (1, 2,100); tsc. addText (20, 20, FONTTYPE. FONT_TAIWAN, ROTATION. ROTATON_0, FONTMUL. MUL_1, FONTMUL. MUL_1, "Hello GPRS Inter"); // draw the text tsc. add1DBarcode (20, 50, BARCODETYPE. CODE128, 100, READABEL. EANBEL, ROTATION. ROTATION_180, "12345"); // draw a one-dimensional Barcode tsc. addPrint (4096,102); // Add the print tag Command Vector <Byte> Command = new Vector <Byte> (4); Command = tsc. getCommand (); // obtain the print command mDevice edited above. sendDataImmediately (Command); // send a Command
2. the ESC command calling template is as follows. The JavaDoc file in the GPRS inter SDK contains the ESCCommand API calling instructions.
EscCommand esc = new EscCommand ();
Esc. addTurnEmphasizedModeOnOrOff (EscCommand. ENABLE. ON); // valid esc in bold mode. addText ("Hello World \ n"); // print the text esc. addUPCA ("123456789012"); // print the UPCA barcode esc. addCODE128 ("uplinter"); // print the CODE128 barcode Vector <Byte> Command = new Vector <Byte> (4096,102 4); Command = esc. getCommand (); // get the edited command data mDevice. sendDataImmediately (Command); // send a Command

After creating an Android project in Eclipse, call the GPRS. jar file. You only need to follow the steps above to edit the desired tag.

 




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.