我想打印到BIXOLON BR200(蓝牙打印机)。
我有一个带有文本和图像的简单页面,我需要打印当前页面或类似内容,但我不知道如何在 Android 中使用PhoneGap进行打印(我也在使用 jQuery 移动版)。
有人可以帮助我吗?
我想打印到BIXOLON BR200(蓝牙打印机)。
我有一个带有文本和图像的简单页面,我需要打印当前页面或类似内容,但我不知道如何在 Android 中使用PhoneGap进行打印(我也在使用 jQuery 移动版)。
有人可以帮助我吗?
我使用 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;
    }
.......
如需完整代码,请联系我。