Method for dynamically connecting Bluetooth printer to print

By using plus.android API and Bluetooth adapter on an Android terminal, dynamically connect to the Bluetooth printer and process the printed content, the problem of poor compatibility between Bluetooth printers and mobile devices in the prior art is solved, and the convenience and reliability of the dynamic Bluetooth printing function is achieved.

CN119917039APending Publication Date: 2025-05-02SHENZHEN AISHIDA INFORMATION TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510075393.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-17
Publication Date
2025-05-02

AI Technical Summary

Technical Problem

When connecting to mobile devices, existing Bluetooth printers need to be set and printed through the manufacturer's APP, which makes it difficult to implement classified printing of different devices and contents, and may have printing errors or problems such as unsuccessful printing.

Method used

The plus.android API calls Android native functions, initialize the Bluetooth adapter and check whether Bluetooth is turned on, obtain device information, establish a Bluetooth connection, process the printed content and generate instructions, and finally send the instructions to the Bluetooth printing device.

Benefits of technology

It realizes dynamic connection between an Android terminal and different Bluetooth printers, and uses two methods to generate commands and print Bluetooth, solving compatibility problems and improving printing convenience and reliability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119917039A_ABST
    Figure CN119917039A_ABST
Patent Text Reader

Abstract

The invention discloses a method for dynamically connecting a Bluetooth printer for printing. The method comprises the following steps: S10, initializing; s20, acquiring equipment information; s30, establishing a Bluetooth connection; s40, the printing content is processed, and instruction generation is conducted in the following two modes according to the printing content: in the first mode, a function for processing characters is packaged to obtain a first instruction, a function for processing a two-dimensional code is packaged to obtain a second instruction, the first instruction and the second instruction are spliced into a complete instruction, and the complete instruction is sent to the printing content; in the second mode, a label template is obtained / designed through a bartender label printing function, then an api interface is requested to obtain a base64 picture, and then the base64 picture is sent to a rear-end api interface to be converted into a zpl instruction; and S50, instruction sending. Dynamic connection between the terminal and different Bluetooth printers is achieved, and instruction generation and Bluetooth printing are carried out on printing content in two modes.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to the technical field of Bluetooth wireless communication, and in particular to a method for dynamically connecting a Bluetooth printer to print. Background Art

[0002] To facilitate people's daily work, existing printers basically support wireless printing, especially small printers and handheld printers (color photo printing) are mainly wireless printing, and the wireless communication methods are mainly Wi-Fi and Bluetooth. Among them, for printers that are not in the same network environment as mobile devices, in order not to cut off the connection between mobile devices and home networks, the common method is still Bluetooth connection printing.

[0003] When existing Bluetooth printers are connected to print via Bluetooth, they generally need to be set up and printed through the manufacturer's APP. However, these APPs are generally not universal for different Bluetooth printers. Forcibly using them may result in printing errors or failure to print.

[0004] In order to realize wireless and convenient printing, Bluetooth printers need to connect with various mobile devices and classify and print different contents for different devices. How to establish a method for dynamic connection between mobile devices and Bluetooth printers so that mobile devices can print with different Bluetooth printers through one APP has become an urgent problem to be solved. Summary of the invention

[0005] In order to solve one or more problems existing in the prior art, the present invention provides a method for dynamically connecting to a Bluetooth printer for printing. The technical solution adopted by the present invention to solve the above problems is: the method comprises: S10, initialization, calling the Android native function through the plus.android API, then initializing the Bluetooth adapter and checking whether the Bluetooth is turned on, and turning on the Bluetooth if it is not turned on;

[0006] S20, device information acquisition, creating a Bluetooth adapter and querying to obtain paired device information, then importing it into the relevant class to obtain a device list, traversing the device list and obtaining corresponding device information, the device information includes a MAC address and a device name, and saving the device information obtained by the traversal cycle into an array;

[0007] S30, establishing a Bluetooth connection, displaying the acquired device information, then selecting a device and acquiring the MAC address of the device, and establishing a Bluetooth connection with the device;

[0008] S40, processing the printed content, and generating instructions according to the printed content in the following two ways. The first way is: encapsulating a function for processing text to obtain a first instruction, encapsulating a function for processing a QR code to obtain a second instruction, and splicing the first instruction and the second instruction into a complete instruction;

[0009] The second method: Get / design the label template through the bartender label printing function, then request the API interface to get the base64 image, and then send the base64 image to the backend API interface to convert it into a zpl instruction;

[0010] S50, command sending, establishing IO and sending the complete command and / or the zpl command to the Bluetooth printing device.

[0011] The technical effect achieved by the present invention is: the dynamic connection between the Android terminal and different Bluetooth printers is realized through the above method, and the printing content is instructed and printed via Bluetooth in two ways, thereby realizing the dynamic Bluetooth printing function between the Android terminal and the Bluetooth printer. BRIEF DESCRIPTION OF THE DRAWINGS

[0012] Figure 1 It is a schematic block diagram of the present invention. DETAILED DESCRIPTION

[0013] In order to make the above-mentioned objects, features and advantages of the present invention more understandable, the specific embodiments of the present invention are described in detail below in conjunction with the accompanying drawings. In the following description, many specific details are set forth to facilitate a full understanding of the present invention. However, the present invention can be implemented in many other ways different from this description, and those skilled in the art can make similar improvements without violating the connotation of the present invention, so the present invention is not limited by the specific embodiments disclosed below.

[0014] The present invention discloses a method for dynamically connecting a Bluetooth printer to print. Figure 1 As shown, the method includes: S10, initialization, calling the Android native function through the plus.android API, then initializing the Bluetooth adapter and checking whether the Bluetooth is turned on, and turning on the Bluetooth if it is not turned on;

[0015] S20, device information acquisition, creating a Bluetooth adapter and querying to obtain paired device information, then importing it into the relevant class to obtain a device list, traversing the device list and obtaining corresponding device information, the device information includes a MAC address and a device name, and saving the device information obtained by the traversal cycle into an array;

[0016] S30, establishing a Bluetooth connection, displaying the acquired device information, then selecting a device and acquiring the MAC address of the device, and establishing a Bluetooth connection with the device;

[0017] S40, processing the printed content, and generating instructions according to the printed content in the following two ways. The first way is: encapsulating a function for processing text to obtain a first instruction, encapsulating a function for processing a QR code to obtain a second instruction, and splicing the first instruction and the second instruction into a complete instruction;

[0018] The second method: Get / design the label template through the bartender label printing function, then request the API interface to get the base64 image, and then send the base64 image to the backend API interface to convert it into a zpl instruction;

[0019] S50, command sending, establishing IO and sending the complete command and / or the zpl command to the Bluetooth printing device.

[0020] Embodiment 1, initialize the Bluetooth adapter and check whether Bluetooth is turned on through the instruction (android.bluetooth.BluetoothAdapter); create a Bluetooth adapter through the instruction (lists = BAdapter.getBondedDevices()); obtain the device list through the instruction (iterator = lists.iterator(), plus.android.importClass(lists), plus.android.importClass(iterator), lists.size()), traverse the loop device list through the instruction (iterator), and determine whether to loop through the instruction (iterator.hasNext()); establish a connection with the Bluetooth device through the instruction (BAdapter.getRemoteDevice(mac));

[0021] Furthermore, for the first method, it can be: encapsulate the function of processing text (createTextDirective (value, option)) to obtain a command similar to ^FO${x},${y}^A@'N',5,12,GB2312_BITMAP^FD${value}, that is, the first command;

[0022] The function (createQRDirective(value,option){}) for encapsulating the QR code processing gets a command similar to ^FO${x},${y}^S50^BQN,2,5^FDHA,${value}, i.e. the second command, and the first and second commands are concatenated into a complete command similar to '^XA'+'xxxxx'+'^XZ'. Then, the IO is established through the command (bluetoothSocket.getOutputStream,plus.android.importClass()), and the command is sent to the Bluetooth printing device, and the printer performs the corresponding printing after receiving it.

[0023] In summary, the above method is used to realize the dynamic connection between the Android terminal and different Bluetooth printers, and the printing content is instructed to be generated and Bluetooth printing is performed in two ways, thereby realizing the dynamic Bluetooth printing function between the Android terminal and the Bluetooth printer.

[0024] The above-described embodiments only express one or more implementation modes of the present invention, and the description thereof is relatively specific and detailed, but it cannot be understood as limiting the patent of the present invention. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present invention, and these all belong to the protection scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the attached claims.

Claims

1. A method for dynamically connecting to a Bluetooth printer for printing, characterized in that: The method comprises: S10, initialization, calling the Android native function through the plus.android API, then initializing the Bluetooth adapter and checking whether the Bluetooth is turned on, and turning on the Bluetooth if it is not turned on; S20, device information acquisition, creating a Bluetooth adapter and querying to obtain paired device information, then importing it into the relevant class to obtain a device list, traversing the device list and obtaining corresponding device information, the device information includes a MAC address and a device name, and saving the device information obtained by the traversal cycle into an array; S30, establishing a Bluetooth connection, displaying the acquired device information, then selecting a device and acquiring the MAC address of the device, and establishing a Bluetooth connection with the device; S40, processing the printing content, and generating instructions according to the printing content in the following two ways: the first way: encapsulating the function of processing text to obtain the first instruction, encapsulating the function of processing QR code to obtain the second instruction, and splicing the first instruction and the second instruction into a complete instruction; the second way: obtaining / designing the label template through the bartender label printing function, and then requesting the API interface to obtain the base64 image, and then sending the base64 image to the backend API interface to convert it into a zpl instruction; S50, command sending, establishing IO and sending the complete command and / or the zpl command to the Bluetooth printing device.