Пример #1
0
 /// <summary>
 /// 获取打印队列
 /// </summary>
 /// <param name="context"></param>
 /// <returns></returns>
 public static PrintQueue GetQueue(Context context)
 {
     if (null == mInstance)
     {
         mInstance = new PrintQueue();
     }
     if (null == mContext)
     {
         mContext = context;
     }
     return(mInstance);
 }
Пример #2
0
        /// <summary>
        /// 启动ConnectedThread开始管理蓝牙连接
        /// </summary>
        /// <param name="socket">建立连接的蓝牙插座</param>
        /// <param name="device">已连接的蓝牙设备</param>
        /// <param name="socketType"></param>
        public static void Connected(BluetoothSocket socket, BluetoothDevice device, string socketType)
        {
            lock (Lock)
            {
                //Log.d(TAG, "connected, Socket Type:" + socketType);

                // 取消完成连接的线程
                if (mConnectThread != null)
                {
                    mConnectThread.Cancel();
                    mConnectThread = null;
                }

                // 取消当前运行连接的任何线程
                if (mConnectedThread != null)
                {
                    mConnectedThread.Cancel();
                    mConnectedThread = null;
                }

                // 取消接受线程,因为我们只想连接到一个设备
                if (mAcceptThread != null)
                {
                    mAcceptThread.Cancel();
                    mAcceptThread = null;
                }

                // 启动线程来管理连接并执行传输
                mConnectedThread = new ConnectedThread(socket);
                mConnectedThread.Start();

                // 将连接设备的名称发送回UI活动
                //EventBus.getDefault().post(new PrintMsgEvent(PrinterMsgType.MESSAGE_TOAST, "蓝牙设备连接成功"));

                SetState(STATE_CONNECTED);

                // 调用打印队列打印
                PrintQueue.GetQueue(mContext).Print();
            }
        }