我想打印到 BIXOLON BR200 (蓝牙打印机)。
我有一个包含文字和图片的简单页面,我需要打印当前页面或类似内容,但我不知道如何使用Android中的 PhoneGap 进行打印(我使用的是jQuery移动也是)。
有人可以帮助我吗?
答案 0 :(得分:1)
我使用BIXOLON Android sdk修复了它并构建了一个插件。这是我的代码:
.....
public PluginResult execute(String action, JSONArray args, String callbackId) {
PluginResult result = null;
context = this.ctx;
// Register for broadcasts when a device is discovered
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
context.registerReceiver(mReceiver, filter);
// Register for broadcasts when discovery starts
filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_STARTED);
context.registerReceiver(mReceiver, filter);
// Register for broadcasts when discovery has finished
filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
context.registerReceiver(mReceiver, filter);
// Register for broadcasts when connectivity state changes
filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
context.registerReceiver(mReceiver, filter);
Looper.prepare();
btadapter= BluetoothAdapter.getDefaultAdapter();
found_devices=new ArrayList<BluetoothDevice>();
try {
try {
Log.d("BluetoothPlugin", "We're in "+ACTION_ENABLE_BT);
boolean enabled = false;
Log.d("BluetoothPlugin", "Enabling Bluetooth...");
if (btadapter.isEnabled())
{
enabled = true;
} else {
enabled = btadapter.enable();
}
Log.d("BluetoothPlugin - "+ACTION_ENABLE_BT, "Returning "+ "Result: "+enabled);
result = new PluginResult(Status.OK, enabled);
} catch (Exception Ex) {
Log.d("BluetoothPlugin - "+ACTION_ENABLE_BT, "Got Exception "+ Ex.getMessage());
result = new PluginResult(Status.ERROR);
}
CheckGC("onCreate_Start");
pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "My Tag");
wl.acquire();
CheckGC("onCreate_End");
CheckGC("Connect_Start");
mBxlService = new BxlService();
int returnValue;
byte[] PINCode = { 0x30, 0x30, 0x30, 0x30 }; // '0'
String bluetoothName = "SPP-R200";
returnValue = mBxlService.SetBluetoothInterface(true, 2, PINCode, bluetoothName);
if (mBxlService.Connect() == 0) {
System.out.println("Conectado");
Log.d("BixolonPlugin", "Conectado");
conn = true;
CheckGC("PrintText_Start");
returnValue = mBxlService.GetStatus();
if (returnValue == BxlService.BXL_SUCCESS) {
String text = args.getString(0);
returnValue = mBxlService.PrintText(text, BxlService.BXL_ALIGNMENT_LEFT,
BxlService.BXL_FT_DEFAULT, BxlService.BXL_TS_0WIDTH | BxlService.BXL_TS_0HEIGHT);
returnValue = mBxlService.LineFeed(5, true);
}
} else {
System.out.println("NO Conectado");
Log.d("BixolonPlugin", "NO Conectado");
conn = false;
}
} catch (Exception e) {
e.printStackTrace();
}
if (mBxlService != null) {
mBxlService.Disconnect();
mBxlService = null;
}
wl.release();
if (DeviceMoldel == HTC_Desire) {
Runtime.getRuntime().exit(0);
}
CheckGC("onDestroy_End");
result = new PluginResult(Status.OK,false);
return result;
}
.......
如果您需要完整的代码,请与我联系。