蓝牙打印机接口

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

一.形码生成器.

1.抽象类:abstract class BarcodeCreater;

2.条形码生成函数Bitmap creatBarcode(Context context(传入的对象), String contents(字串的内容),

int desiredWidth(宽度), int desiredHeight(高度), boolean displayCode(生成字串),

int barType(固定值1)) ;//其中displayCode为true生成的图片比实际高度大24;返回值是BitMap类型的;

3.二维码生成函数Bitmap encode2dAsBitmap(String contents(字串的内容), int desiredWidth(宽度), int desiredHeight(高度), int barType(固定值2));返回值MitMap类型的。

4.保存图片public static boolean saveBitmap2file(Bitmap bmp(原Bitmap图片), String filename (文件路径));

二.蓝牙设备接口:

1.类名BlueToothService;new 对象的时候public BlueToothService(Context context, Handler

handler);

2.检测是否有蓝牙设备public boolean HasDevice();

3.检测是否打开蓝牙设备:public boolean IsOpen();

4.打开蓝牙设备:void OpenDevice();

5.关闭蓝牙设备void CloseDevice();

6.扫描蓝牙设备public void ScanDevice(),但是要有一个回调事件例如:

mBTService对象名

mBTService.setOnReceive(new OnReceiveDataHandleEvent() {

@Override

public void OnReceive(BluetoothDevice device) {

// TODO Auto-generated method stub

if (device != null) {

mNewDevicesArrayAdapter.add(device.getName() + "\n"

+ device.getAddress());//接收到的蓝牙设备

} else {

//扫描完毕

}

}

});

7.停止扫描void StopScan();

8.连接到蓝牙设备:void ConnectToDevice(String address)//参数物理地址;

获取当前扫描状态:int GetScanState()返回值public static final int STATE_SCANING = 0;//

扫描状态public static final int STATE_SCAN_STOP = 1;两种状态

9.断开连接DisConnected();

10.打印字串void PrintCharacters(String str);

11.打印指令void SendOrder(byte[] send)

12.打印图片void PrintImageOld (Bitmap bitmapCode)(旧版打印机)

打印图片void PrintImageNew (Bitmap bitmapCode)(新版打印机)

13.蓝牙连接状态和打印机状态都是依靠message来传递给外面的,具体状态有

public static final int MESSAGE_STATE_CHANGE = 1;//蓝牙状态

public static final int MESSAGE_READ = 2;

public static final int MESSAGE_WRITE = 3;

14.获取当前状态int getState()

public static final int STATE_NONE = 0; // we're doing nothing

public static final int STATE_LISTEN = 1; // now listening for incoming public static final int STATE_CONNECTING = 2; //正在连接

public static final int STATE_CONNECTED = 3;//已经连接

public static final int LOSE_CONNECT = 4;//丢失连接

public static final int FAILED_CONNECT = 5;//连接失败

public static final int SUCCESS_CONNECT = 6; // 连接成功

具体请参考demo中handler

mhandler = new Handler() {

public void handleMessage(Message msg) {

super.handleMessage(msg);

switch (msg.what) {

case MESSAGE_STATE_CHANGE:// 蓝牙连接状态

switch (msg.arg1) {

case BlueToothService.STATE_CONNECTED:// 已经连接

break;

case BlueToothService.STATE_CONNECTING:// 正在连接

break;

case BlueToothService.STATE_LISTEN:

case BlueToothService.STATE_NONE:

break;

case BlueToothService.SUCCESS_CONNECT:

Toast.makeText(MainActivity.this, "连接成功", 2000).show();

vg.getChildAt(0).setVisibility(View.GONE);

vg.getChildAt(1).setVisibility(View.GONE);

vg.getChildAt(2).setVisibility(View.VISIBLE);

vg.getChildAt(2).setFocusable(true);

vg.getChildAt(2).setFocusableInTouchMode(true);

break;

case BlueToothService.FAILED_CONNECT:

Toast.makeText(MainActivity.this, "连接失败", 2000).show();

vg.getChildAt(0).setVisibility(View.VISIBLE);

vg.getChildAt(1).setVisibility(View.VISIBLE);

相关文档
最新文档