Professional Documents
Culture Documents
Summary
ThisSDKpackageisforAndroidapplication,communicatetheprinterwithBluetooth
connections.Itcanbedividedinto2maintypes.OneisbluetoothoperationType
andotherforImageprintingandprocessing.
com.zj.btsdk
TypeBluetoothService
java.lang.Object
com.zj.btsdk.BluetoothService
BluetoothServiceTypeforBluetoothoperation(e.g.Bluetoothconnection,
Bluetoothdatatransmitting,Bluetoothdevicesearchingetc.)
com.zj.btsdk
TypePrintPic
java.lang.Object
com.zj.btsdk.PrintPic
PrintPicTypeforimageprintingandprocessing(decomposethedesiredimagesinto
easilyrecognizabledatastream)
SchematicDiagram
AndroidapplicationprogrammingcallsthecorrespondinginterfacefromBluetooth
SDKpackage(e.g.connectingtheBluetoothinterface),andmeanwhilereceivingthe
messagessentbackfromthebluetoothSDKpackage(e.g.connectingfailurenotice).
Androidapplicationprogrammingcouldcallsthesendingprintfunction,andsending
theprintingcommandtoBluetoothPrinterinoneway.
BluetoothSDKPackage
Androidprogramcallsinterfacefromsdkpackage&
receivetheinforeturnedfromtheBluetoothSDK
SendingPrintcommand
AndroidProgramming BluetoothPrinter
Descriptionindetailfortheinterfacetype
TypeBluetoothService
Fielddescription
Field Description
BluetoothService.MESSAGE_STATE_CHANGE ReturningtheBluetoothconnection
infotoAndroidprogramming
BluetoothService.MESSAGE_CONNECTION_L FeedbacktheBluetooth
OST disconnectedinfotoandroid
programming
BluetoothService.MESSAGE_UNABLE_CONNE FeedbacktheBluetoothconnection
CT failuretoandroidprogramming
BluetoothService.STATE_NONE Thissignindicatesnoneoperations
forthisBluetoothdevice
BluetoothService.STATE_LISTEN indicatesthisBTdevicearelistening
theBluetoothcommunication
BluetoothService.STATE_CONNECTED Indicatesalreadyconnectedwitha
Bluetoothdevice
BluetoothService.STATE_CONNECTING meanstheandroidBTareconnecting
anotherBluetoothdevice
Interfacedescription
Constructedfunction
publicBluetoothService(Contextcontext,Handlerhandler)
Functiondescription
Initializationofclassfield
Parameterdescription
Handler:AfferentaHanderinstance,usedforSDKpackagereturnthemessagestoandroidapplication
programming.
Ordinaryfunction
a. isAvailable
FunctionPrototypepublicsynchronizedbooleanisAvailable()
FunctionDescription
Judgeandensuretheandroiddevice&Bluetoothhardwareisusable.
Returnvaluedescription
True:Bluetoothavailable
False:Bluetoothnotavailable
bisBTopen
FunctionPrototypepublicsynchronizedbooleanisBTopen()
Functiondescription
Judgeandensuretheandroidbluetoothdeviceisturnedon.
Returnvaluedescription
True:Bluetoothturnson
False:Bluetoothisntturnedon
cgetDevByMac
FunctionPrototypepublicsynchronizedBluetoothDevicegetDevByMac(Stringmac)
FunctionDescription:
Getadeviceinstanceaccordingtothedevicemacaddress
ParameterDescriptionmacBluetoothprintermacaddress
ReturnValueDescription
True:returnaBluetoothDeviceinstance
False:null
d. sendMessage
FunctionPrototypepublicsynchronizedvoidsendMessage(Stringmessage,String
charset)
FunctionDescription
Transcodingtheprintinginformationaccordingtodesiredcharacterset,and
sendtheprintingcommandtoprinter.
Message Printinginformationcharacterstring
CharsetCharactersetencodinge.g.GBK
e. write
FunctionPrototypepublicvoidwrite(byte[]out)
FunctionDescription
Sendingofbytestreamdatatobluetoothprinter(e.g.wecanusethisfunction
whenwehavetosendtheprintercontrolinstruction)
FunctionDescription
Out:Bytestreamdatastobesend
f.getPairedDev
FunctionPrototypepublicsynchronizedSet<BluetoothDevice>getPairedDev()
FunctionDescription
Gettheconnecteddevicesset
ReturnValueDescription
Gettheconnecteddevicesset
g. cancelDiscovery
FunctionPrototypepublicsynchronizedboolean cancelDiscovery()
FunctionDescription
Cancellingofthedevicesearchingoperation.
ReturnValueDescription
True:successreturned
False:failed
hstartDiscovery
FunctionPrototypepublicsynchronizedbooleanstartDiscovery()
FunctionDescription
Startingofasearchingoperation
ReturnValueDescription
Successreturned:trueFailed:false
igetState
FunctionPrototypepublicsynchronizedintgetState()
FunctionDescription
Gettheontimebluetoothconnectionstatus.
ReturnValueDescription
BluetoothService.STATE_NONENoConnection
BluetoothService.STATE_LISTEN:Listeningtotheconnection
BluetoothService.STATE_CONNECTEDAlreadyConnected
BluetoothService.STATE_CONNECTING:ConnectingProcess
jconnect
FunctionPrototypepublicsynchronizedvoidconnect(BluetoothDevicedevice)
FunctionDescription
BluetoothConnectingrequested.
ParameterDescription
Device AfferentBluetoothDevice
kstop
FunctionPrototypepublicsynchronizedvoidstop()
FunctionDescription
Disconnectingthebluetoothandreleasetheoccupieddatas.
TypePrintPic
Ordinaryfunction
a. initCanvas
FunctionPrototypepublicvoidinitCanvas(intw)
FunctionDescription
Initializecanvas
ParameterDescription
W:Value384pxfor58seriesprinter Value576pxfor80seriesprinter
b. initPaint
FunctionPrototypepublicvoidinitPaint()
FunctionDescription:
Initializebrush
c. drawImage
FunctionPrototypepublicvoiddrawImage(floatx,floaty,Stringpath)
FunctionDescription
Paintingthepathspecifiedimageonthecanvas
ParameterDescription
PathImagepath
(x,y):Leftvertexcoordinates
dprintDraw
FunctionPrototypepublicbyte[]printDraw()
FunctionDescription returningoftheimagebytestreamonthecanvas(easily
recognizabledatastreamfortheprinter)
e.g.
byte[]sendData=null;
PrintPicpg=newPrintPic();
pg.initCanvas(384);
pg.initPaint();
pg.drawImage(0,0,"/mnt/sdcard/icon.jpg");
sendData=pg.printDraw();
FinallyforwardthesendDatatobluetoothPrinterforimageprinting.
DemoProgram
PleaserefertoPrintDemoforbluetoothprinterforDetail(Demoprogramforthis
SDK)
DevelopmenttoolAndroidDeveloperToolsBuild:v21.0.1543035