洗涤厂自动汇总月度台账-蓝牙打印单据源码 CyberWinApp-SAAS 本地化及未来之窗行业应用跨平台架构

司机收布草现场打印,是比较常用的功能

一、android 调用蓝牙打印

@JavascriptInterface
	public String cyber_TestPopPrinter() {

		try {
			View view = LayoutInflater.from(cyber_cpu_main).inflate(R.layout.蓝牙界面, null);
			ListView mListView = (ListView) view.findViewById(R.id.lv_bluetooth_printerlist);
			TextView m_title = (TextView) view.findViewById(R.id.lv_bluetooth_printerlist_title);
			m_title.setText("请选择打印机-雪莲计划");

			IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
			filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
			cyber_cpu_main.cyber_registerReceiver(mReceiver, filter);

			//registerReceiver(mReceiver, filter); // Don't forget to unregister during onDestroy
			//初始化
			//LogToFile.d("蓝牙2","初始化");
			Cyber_Public_Var.mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
			//mSwitch = (Switch) findViewById(R.id.switch1);
			//mFloatingActionButton = (Button) findViewById(R.id.cyber_btn_1);
			//mProgressBar = (ProgressBar) findViewById(R.id.progressBar3);
			// toolbar = (Toolbar) findViewById(R.id.toolbar);
			//	searchHint = (TextView) findViewById(R.id.searchHint);
			//  toolbar.setTitle("选择打印设备");

			//listView = (ListView) findViewById(R.id.listView);
			Cyber_Public_Var.mBluetoothDevicesDatas = new ArrayList<>();

			String printContent = "wlwllw";
			//	Cyber_Public_Var.adapter = new cyber_20190921_PrintAdapter(cyber_cpu_main, Cyber_Public_Var.mBluetoothDevicesDatas, printContent);
			//	mListView.setAdapter(Cyber_Public_Var.adapter);

			mBluetoothList2 = new ArrayList<>();
			//	for (BluetoothBean bean : mBluetoothList) {
			//	boolean add = set.add(bean);
			BluetoothBean bean = new BluetoothBean();
			bean.mBluetoothAddress = 蓝牙地址;
			//"DC:0D:30:7E:8E:8D";
			bean.mBluetoothName = "未来之窗蓝牙设备";

			mBluetoothList2.add(bean);


			//mBluetoothList2.add()

			MyBluetoothAdapter myBluetoothAdapter = new MyBluetoothAdapter();
			mListView.setAdapter(myBluetoothAdapter);

			LogToFile.d("蓝牙技术-雪莲", "初始化2");

			chechBluetooth();
			addViewListener();

			LogToFile.d("蓝牙技术-雪莲", "初始化-成功");


			PopupWindow pw;


			mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
				@Override
				public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
					if (0 != mBluetoothList2.size()) {
						showToast("开始打印");
						new ConnectThread(Cyber_Public_Var.mBluetoothAdapter.getRemoteDevice("DC:0D:30:7E:8E:8D")).start();
						//connect(bluetoothList.get(position).mBluetoothAddress, bluetoothList.get(position).mBluetoothDevice);
					}
				}
			});
			pw = new PopupWindow(view, (int) (MyApplication.cyber_ScreenWidth * 0.8), -2);
			MyApplication.closePopupWindow(pw);
			pw.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
			pw.setOutsideTouchable(true);
			pw.setFocusable(true);

			//	cyber_cpu_main.getWindow().setAttributes(lp);
			//cyber_cpu_main.cyber_setWindAlpha(0.6f);

			pw.setOnDismissListener(new PopupWindow.OnDismissListener() {

				@Override
				public void onDismiss() {

					//	cyber_cpu_main.cyber_setWindAlpha(1f);
				}
			});
			pw.setAnimationStyle(R.style.PopAnim);
			//显示
			pw.showAtLocation(view, Gravity.CENTER, 0, 0);
		} catch (Exception ex) {
			showToast(ex.getMessage());
			LogToFile.d("窗口", ex.getMessage());
		}
		return "0";
	}

二、封装为模块webview调用蓝牙打印

BluetoothDevice device =  mBluetoothAdapter.getRemoteDevice(蓝牙地址);
					//打印全局不许设置
				 mmSocket = device.createRfcommSocketToServiceRecord(uuid);

					 
					OutputStream out_blue = mmSocket.getOutputStream();
					out_blue.write(打印数据);
					out_blue.close();
					mmSocket.close();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值