Bluetooth connection method, device, electronic device and storage medium
By using flag bits during Bluetooth connection to determine the status of the device identification comparison, avoiding repeated calls to the Bluetooth connection interface, the problem of low Bluetooth connection efficiency and accuracy in the existing technology is solved, and more efficient and accurate Bluetooth connection is achieved.
Patent Information
- Application Number
- CN202211435488.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-16
- Publication Date
- 2025-05-13
- Estimated Expiration
- 2042-11-16
AI Technical Summary
In the prior art, when multiple connectable Bluetooth devices are called multiple times, the connection interface of the SDK is called, resulting in a longer transmission delay and the call interface duration, which affects the efficiency and accuracy of Bluetooth connection.
The target Bluetooth device to be connected through user operations is determined and its device identification is obtained. Based on the terminal's Bluetooth scanning function, unconnected Bluetooth devices are found, and a flag is used to determine whether the device identification comparison has been performed. If no judgment is made, compare the device identifier of the target Bluetooth device with the device identifier of the unconnected device and update the flag to avoid repeated comparisons. If both are consistent, connect to an unconnected Bluetooth device and turn off Bluetooth scanning.
It improves the efficiency and accuracy of Bluetooth connection, reduces transmission delay and multiple connection information feedback, and improves the user experience.
Smart Images

Figure CN115811806B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to communication technology, and in particular to a method, device, electronic device and storage medium for Bluetooth connection. Background Art
[0002] When the terminal is connected to Bluetooth, the Bluetooth scanning interface of the SDK (Software Development Kit) is called to retrieve the Bluetooth devices that can be connected near the terminal. After obtaining the Bluetooth devices that can be connected nearby, the Bluetooth connection interface of the SDK is called to connect the Bluetooth devices.
[0003] In the prior art, if there are multiple connectable Bluetooth devices, the SDK connection interface is called multiple times, which takes a long time to call the interface, affecting the efficiency and accuracy of the Bluetooth connection. Summary of the invention
[0004] The present application provides a Bluetooth connection method, device, electronic device and storage medium to improve the accuracy and efficiency of Bluetooth connection.
[0005] In a first aspect, the present application provides a Bluetooth connection method, which is applied to a terminal and includes:
[0006] In response to a Bluetooth device connection operation issued by a user through a visual interface of a terminal, determining a device identifier of a target Bluetooth device to be connected to the terminal; wherein the device identifier is used to represent a Bluetooth device;
[0007] Based on the Bluetooth scanning function of the terminal, discovering unconnected Bluetooth devices within a preset range of the terminal;
[0008] If it is determined that the preset first flag bit is a preset initial value, the device identification of the unconnected Bluetooth device is determined, and the first flag bit is updated from the initial value to a preset target value; wherein the first flag bit is used to indicate the judgment state of the terminal for judging the two device identifications, the judgment state includes no judgment and judgment, the initial value of the first flag bit indicates that the judgment state of the terminal for judging the two device identifications is in a state of no judgment, and the target value of the first flag bit indicates that the judgment state of the terminal for judging the two device identifications is in a state of judgment;
[0009] If it is determined that the device identification of the target Bluetooth device is consistent with the device identification of the unconnected Bluetooth device, the unconnected Bluetooth device is connected and the Bluetooth scanning function is turned off.
[0010] In a second aspect, the present application provides a Bluetooth connection device, which is applied to a terminal and includes:
[0011] A first determination module, configured to determine a device identifier of a target Bluetooth device to be connected to the terminal in response to a Bluetooth device connection operation issued by a user through a visual interface of the terminal; wherein the device identifier is used to represent the Bluetooth device;
[0012] A device scanning module, used to find unconnected Bluetooth devices within a preset range of the terminal based on the Bluetooth scanning function of the terminal;
[0013] A second determination module is used to determine the device identification of the unconnected Bluetooth device if it is determined that the preset first flag bit is a preset initial value, and update the first flag bit from the initial value to a preset target value; wherein the first flag bit is used to indicate the judgment state of the terminal for judging the two device identifications, the judgment state includes no judgment and judgment, the initial value of the first flag bit indicates that the judgment state of the terminal for judging the two device identifications is in a state of no judgment, and the target value of the first flag bit indicates that the judgment state of the terminal for judging the two device identifications is in a state of judgment;
[0014] The device connection module is used to connect the unconnected Bluetooth device and disable the Bluetooth scanning function if it is determined that the device identification of the target Bluetooth device is consistent with the device identification of the unconnected Bluetooth device.
[0015] In a third aspect, the present application provides an electronic device, comprising: a processor, and a memory communicatively connected to the processor;
[0016] The memory stores computer-executable instructions;
[0017] The processor executes the computer-executable instructions stored in the memory to implement the Bluetooth connection method as described in the first aspect of the present application.
[0018] In a fourth aspect, the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are executed by a processor, they are used to implement the Bluetooth connection method as described in the first aspect of the present application.
[0019] In a fifth aspect, the present application provides a computer program product, including a computer program, which, when executed by a processor, implements the Bluetooth connection method as described in the first aspect of the present application.
[0020] The present application provides a method, device, electronic device and storage medium for Bluetooth connection. Through user operation, the target Bluetooth device to be connected is determined, and the device identification of the target Bluetooth device is obtained. According to the Bluetooth scanning function of the terminal, it is determined whether there is an unconnected Bluetooth device within the preset range of the terminal. If it exists, it is determined whether the first flag is a preset initial value. If so, the device identification of the unconnected Bluetooth device is determined, the device identification of the target Bluetooth device is compared with the device identification of the unconnected Bluetooth device, and the first flag is updated from the initial value to the preset target value to avoid calling the Bluetooth connection interface again during the comparison process. If it is determined that the device identification of the target Bluetooth device is consistent with the device identification of the unconnected Bluetooth device, the unconnected Bluetooth device is connected, and the Bluetooth scanning function is turned off to avoid the terminal from continuing to scan and making repeated judgments. In the prior art, the SDK interface is called multiple times in the process of connecting a Bluetooth device, resulting in transmission delays and long calling interface times. Avoid multiple connections and feedback of multiple connection information, improve the efficiency and accuracy of Bluetooth connections, and enhance user experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0022] Figure 1 A schematic diagram of a flow chart of a Bluetooth connection method provided in an embodiment of the present application;
[0023] Figure 2 A schematic diagram of a flow chart of a Bluetooth connection method provided in an embodiment of the present application;
[0024] Figure 3 A structural block diagram of a Bluetooth connection device provided in an embodiment of the present application;
[0025] Figure 4 A structural block diagram of a Bluetooth connection device provided in an embodiment of the present application;
[0026] Figure 5 A structural block diagram of an electronic device provided in an embodiment of the present application;
[0027] Figure 6 A structural block diagram of an electronic device provided in an embodiment of the present application.
[0028] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION
[0029] In order to make the objectives, technical solutions and advantages of the present application more clear, the embodiments of the present application will be further described in detail below with reference to the accompanying drawings.
[0030] It should be clear that the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without creative work are within the scope of protection of the present application.
[0031] When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. Instead, they are only examples of devices and methods consistent with some aspects of the present application as detailed in the attached claims.
[0032] In the description of the present application, it should be understood that the terms "first", "second", "third", etc. are only used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence, nor can they be understood as indicating or implying relative importance. For those of ordinary skill in the art, the specific meanings of the above terms in the present application can be understood according to the specific circumstances. In addition, in the description of the present application, unless otherwise specified, "multiple" refers to two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the objects associated before and after are in an "or" relationship.
[0033] It should be noted that due to space limitations, this application specification does not list all optional implementation methods. After reading this application specification, those skilled in the art should be able to think that as long as the technical features do not contradict each other, any combination of technical features can constitute an optional implementation method. Each embodiment is described in detail below.
[0034] In the development of mobile terminals, when calling some device functions, for example, when making a Bluetooth connection, it is necessary to call an API (Application Programming Interface) provided by the native layer.
[0035] When making a Bluetooth connection, call the Bluetooth scanning API interface implemented by the native SDK to retrieve the Bluetooth devices that can be connected near the terminal. After obtaining the nearby connectable Bluetooth devices, the Bluetooth devices can be compared one by one according to the expected conditions pre-set by the user. For example, the expected conditions can be the name of the Bluetooth device that is expected to be connected to Bluetooth. Find the Bluetooth device that meets the expected conditions, call the Bluetooth connection API interface implemented by the native SDK, and connect to the Bluetooth device.
[0036] However, when connecting to a Bluetooth device, the API interface is still being called to query the Bluetooth device information and try to connect to the Bluetooth. Multiple calls to the interface will cause transmission delays and long calls to the interface. Multiple connections will occur, that is, multiple Bluetooth connection operations are performed simultaneously within a short period of a few seconds, and multiple connection information is fed back. The user perceives that multiple devices are connected at the same time, affecting the efficiency and accuracy of the Bluetooth connection.
[0037] The present application provides a Bluetooth connection method, device, electronic device and storage medium, aiming to solve the above technical problems in the prior art.
[0038] The technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.
[0039] Figure 1 1 is a flow chart of a method for Bluetooth connection provided according to an embodiment of the present application. The method is applied to a terminal and can be executed by a Bluetooth connection device. Figure 1 As shown, the method comprises the following steps:
[0040] S101. In response to a Bluetooth device connection operation issued by a user through a visual interface of a terminal, determine a device identifier of a target Bluetooth device to be connected to the terminal; wherein the device identifier is used to represent the Bluetooth device.
[0041] Exemplarily, the terminal may be a terminal device such as a mobile phone or a computer. In this embodiment, the terminal has a Bluetooth connection function. The user may turn on the Bluetooth of the terminal, and the terminal may scan nearby Bluetooth devices and display the scanned nearby Bluetooth devices on a visual interface of the terminal. For example, the terminal may scan Bluetooth devices within a preset radius with the terminal as the center. The Bluetooth devices may be devices such as headphones, mobile phones, and keyboards.
[0042] The user can view nearby Bluetooth devices through the terminal visualization interface, and the user can select one of the Bluetooth devices as the target Bluetooth device and issue a Bluetooth device connection operation to the target Bluetooth device. The target Bluetooth device is the Bluetooth device to be connected with the terminal, that is, the user expects the terminal to connect with the target Bluetooth device. For example, the user can click on the target Bluetooth device to instruct the terminal to connect with the target Bluetooth device, that is, the click operation can be a Bluetooth connection operation, and the clicked Bluetooth device is the target Bluetooth device.
[0043] Each Bluetooth device has a unique device identifier, which can be used to represent the Bluetooth device. For example, the device identifier can be the factory number or device name of the device. After determining the target Bluetooth device selected by the user, the device identifier of the target Bluetooth device is determined. For example, the device number of the target Bluetooth device is "001". The user can also enter the device identifier of the Bluetooth device on the visual interface of the terminal. The Bluetooth device corresponding to the entered device identifier is the target Bluetooth device, and the device identifier of the target Bluetooth device is obtained.
[0044] In this embodiment, in response to a Bluetooth device connection operation issued by a user through a visual interface of a terminal, a device identification of a target Bluetooth device to be connected to the terminal is determined, including: according to a connection operation issued by a user on the visual interface of the terminal to any selected Bluetooth device, any selected Bluetooth device is determined as a target Bluetooth device to be connected to the terminal; and the device identification of the target Bluetooth device is determined.
[0045] Specifically, after turning on Bluetooth, the terminal starts scanning Bluetooth devices, and displays the scanned Bluetooth devices on the visual interface of the terminal. The user can select any Bluetooth device from the scanned Bluetooth devices as the target Bluetooth device, and instruct the terminal to connect to the target Bluetooth device through Bluetooth. For example, the user can make a connection operation for any Bluetooth device in the visual interface, and the connection operation can be a click operation of the user, that is, the user can click the target Bluetooth device on the interface. The Bluetooth device clicked by the user is the target Bluetooth device selected by the user.
[0046] After determining the target Bluetooth device, obtain the device identification of the target Bluetooth device, for example, the device name of the target Bluetooth device on the visual interface can be used as the device identification. In this embodiment, after scanning a Bluetooth device near the terminal, the terminal can pause scanning of nearby Bluetooth devices or continue scanning nearby Bluetooth devices.
[0047] The beneficial effect of such a setting is that the user can select the target Bluetooth device according to actual needs, thereby improving the flexibility of the Bluetooth connection.
[0048] S102: Based on the Bluetooth scanning function of the terminal, an unconnected Bluetooth device is discovered within a preset range of the terminal.
[0049] Exemplarily, after determining the device identification of the target Bluetooth device, the terminal can turn on the Bluetooth scanning function. If the terminal has always turned on the Bluetooth scanning function, the Bluetooth scanning can continue. Determine whether there is an unconnected Bluetooth device within a preset range. The preset range can be a range within a preset radius centered on the terminal. The scanned Bluetooth device can be the same as or different from the Bluetooth device displayed on the visual interface. For example, if the terminal is a computer, it can scan nearby unconnected Bluetooth devices such as headphones, keyboards, and mice.
[0050] If an unconnected Bluetooth device is found within the preset range of the terminal, S103 can be executed, that is, it is not necessary to discover all Bluetooth devices within the preset range of the terminal before executing S103, so as to avoid the terminal from performing long-term scanning and improve the efficiency of Bluetooth connection. S103 can also be executed after a preset number of unconnected Bluetooth devices are found. For example, S103 is executed after three Bluetooth devices are found, so as to avoid the terminal from performing frequent scanning in the future, reduce the number of scans, and improve the efficiency of Bluetooth connection.
[0051] S103. If it is determined that the preset first flag bit is the preset initial value, the device identification of the unconnected Bluetooth device is determined, and the first flag bit is updated from the initial value to the preset target value; wherein the first flag bit is used to indicate the judgment state of the terminal for judging the two device identifications, the judgment state includes no judgment and judgment, the initial value of the first flag bit indicates that the judgment state of the terminal for judging the two device identifications is in a state of no judgment, and the target value of the first flag bit indicates that the judgment state of the terminal for judging the two device identifications is in a state of judgment.
[0052] Exemplarily, a first flag is pre-set, and the first flag is used to indicate the judgment state of the terminal for judging the two device identifiers. The terminal judging the two device identifiers means that the terminal compares and judges the device identifier of the target Bluetooth device with the device identifier of the scanned Bluetooth device. The judgment state includes a state where no judgment is made and a state where judgment is made. The first flag can be preset with two values, including an initial value and a target value. The initial value of the first flag indicates that the judgment state of the terminal for judging the two device identifiers is in a state where no judgment is made, and the target value of the first flag indicates that the judgment state of the terminal for judging the two device identifiers is in a state where judgment is made. For example, the initial value is 0, and the target value is 1. If the first flag is 0, it means that the terminal has not compared the device identifiers; if the first flag is 1, it means that the terminal is comparing the device identifiers.
[0053] After determining that there is an unconnected Bluetooth device within the preset range of the terminal, determine whether the first flag is an initial value, that is, whether the terminal is currently performing a device identification comparison. If it is an initial value, that is, it is determined that the terminal is not currently performing a device identification comparison, then obtain the device identification of the scanned unconnected Bluetooth device, so as to compare the device identification of the scanned unconnected Bluetooth device with the device identification of the target Bluetooth device. After obtaining the device identification of the unconnected Bluetooth device, the first flag can be updated from the initial value to the target value. For example, change the first flag from 0 to 1.
[0054] If it is determined that the first flag bit is not the initial value but the target value, it means that the terminal is currently determining the device identification and does not compare the device identification of the currently scanned unconnected Bluetooth device with the device identification of the target Bluetooth device, thereby reducing interface calls and avoiding multiple connection information feedback.
[0055] In this embodiment, after an unconnected Bluetooth device is found within a preset range of the terminal based on the Bluetooth scanning function of the terminal, it also includes: if it is determined that the preset first flag bit is a preset target value, the first flag bit is monitored according to a preset monitoring period; if it is determined that the first flag bit is updated from the target value to the initial value, the device identification of the unconnected Bluetooth device is determined, and the first flag bit is updated from the initial value to the preset target value.
[0056] Specifically, if it is determined that the first flag bit is currently the target value, it means that the terminal is currently determining the device identification, and it is necessary to wait until the terminal completes the current determination before making a new determination. Therefore, it is necessary to monitor whether the first flag bit becomes the initial value. The first flag bit can be monitored in real time or periodically, for example, a monitoring cycle is preset, and according to the preset monitoring cycle, the first flag bit is regularly determined to be the target value or the initial value.
[0057] If it is determined that the first flag bit changes from the target value to the initial value, it means that the terminal has completed the previous judgment process. If the previously judged unconnected Bluetooth device is not the target Bluetooth device, the device identification of the currently unconnected Bluetooth device can be determined, and the first flag bit is updated from the initial value to the preset target value. That is, after determining that there is an unconnected Bluetooth device, the device identification is not necessarily judged immediately. The device is judged only when the first flag bit is the initial value, and when the judgment begins, the second flag bit is adjusted to the target value in time to avoid judging other Bluetooth devices.
[0058] The beneficial effect of such a setting is that it avoids calling other interfaces multiple times when calling a connection interface of a Bluetooth device, so that the terminal will not feedback multiple connection information, avoids incorrect feedback information received by the user, improves the accuracy of Bluetooth connection, and enhances user experience.
[0059] S104: If it is determined that the device identification of the target Bluetooth device is consistent with the device identification of the unconnected Bluetooth device, the unconnected Bluetooth device is connected and the Bluetooth scanning function is turned off.
[0060] For example, after obtaining the device identification of the currently scanned unconnected Bluetooth device, the device identification of the target Bluetooth device is compared with the device identification of the unconnected Bluetooth device to determine whether the two are consistent. If they are consistent, it is determined that the currently scanned unconnected Bluetooth device is the target Bluetooth device, and the terminal can connect to the unconnected Bluetooth device with Bluetooth, and turn off the Bluetooth scanning function to avoid the terminal from continuing to scan and repeatedly judging; if they are inconsistent, it is determined that the currently scanned unconnected Bluetooth device is not the target Bluetooth device, and the terminal needs to continue scanning the Bluetooth device and judging the device identification.
[0061] In this embodiment, after determining the device identification of the unconnected Bluetooth device and updating the first flag bit from the initial value to the preset target value, it also includes: if it is determined that the device identification of the target Bluetooth device is inconsistent with the device identification of the unconnected Bluetooth device, the first flag bit is updated from the target value to the preset initial value.
[0062] Specifically, if it is determined that the unconnected Bluetooth device is the target Bluetooth device, the first flag bit can be reset to the initial value after the Bluetooth scanning function is turned off, so as to facilitate the judgment of the device identification when Bluetooth is turned on next time. If it is determined that the unconnected Bluetooth device is not the target Bluetooth device, the first flag bit is updated from the target value to the initial value, and the terminal can obtain the device identification of the newly scanned unconnected Bluetooth device and judge the device identification again.
[0063] If an unconnected Bluetooth device is found when executing S102, S103 is started, and S102 is executed again after determining that the device identifier of the target Bluetooth device is inconsistent with the device identifier of the unconnected Bluetooth device; if multiple unconnected Bluetooth devices are found when executing S102, S103 is executed after determining that the device identifier of the target Bluetooth device is inconsistent with the device identifier of one of the unconnected Bluetooth devices, and S102 is executed again after all the multiple unconnected Bluetooth devices found are judged.
[0064] The beneficial effect of such a setting is that if the target Bluetooth device is not found, the first flag bit is updated in time, which facilitates subsequent judgment of other Bluetooth devices and improves the efficiency of Bluetooth connection.
[0065] A method for Bluetooth connection provided by an embodiment of the present application determines the target Bluetooth device to be connected through user operation, and obtains the device identification of the target Bluetooth device. According to the Bluetooth scanning function of the terminal, it is determined whether there is an unconnected Bluetooth device within the preset range of the terminal. If it exists, it is determined whether the first flag is a preset initial value. If so, the device identification of the unconnected Bluetooth device is determined, the device identification of the target Bluetooth device is compared with the device identification of the unconnected Bluetooth device, and the first flag is updated from the initial value to the preset target value to avoid calling the Bluetooth connection interface again during the comparison process. If it is determined that the device identification of the target Bluetooth device is consistent with the device identification of the unconnected Bluetooth device, the unconnected Bluetooth device is connected, and the Bluetooth scanning function is turned off to avoid the terminal from continuing to scan and making repeated judgments. In the prior art, the SDK interface is called multiple times in the process of connecting a Bluetooth device, resulting in transmission delays, long calling interface duration, and other problems. Avoid multiple connections and feedback of multiple connection information, improve the efficiency and accuracy of Bluetooth connections, and enhance user experience.
[0066] Figure 2 A flowchart of a Bluetooth connection method provided in an embodiment of the present application is provided. This embodiment is an optional embodiment based on the above embodiment.
[0067] In this embodiment, based on the Bluetooth scanning function of the terminal, an unconnected Bluetooth device is found within a preset range of the terminal, which can be further refined as follows: if based on the Bluetooth scanning function of the terminal, at least one unconnected Bluetooth device is found within a preset range of the terminal, the preset second flag bit is updated from a preset first value to a second value; wherein the second flag bit is used to indicate the scanning result of the terminal for the unconnected Bluetooth device; the scanning result includes finding an unconnected Bluetooth device and not finding an unconnected Bluetooth device; the first value indicates that no unconnected Bluetooth device is found, and the second value indicates that an unconnected Bluetooth device is found.
[0068] like Figure 2 As shown, the method comprises the following steps:
[0069] S201. In response to a Bluetooth device connection operation issued by a user through a visual interface of a terminal, determine a device identifier of a target Bluetooth device to be connected to the terminal; wherein the device identifier is used to represent the Bluetooth device.
[0070] Exemplarily, this step may refer to the above-mentioned step S101 and will not be described in detail.
[0071] S202. If at least one unconnected Bluetooth device is found within a preset range of the terminal based on the Bluetooth scanning function of the terminal, the preset second flag bit is updated from the preset first value to the second value; wherein the second flag bit is used to indicate the scanning result of the terminal for the unconnected Bluetooth device; the scanning result includes finding an unconnected Bluetooth device and not finding an unconnected Bluetooth device; the first value indicates that no unconnected Bluetooth device is found, and the second value indicates that an unconnected Bluetooth device is found.
[0072] Exemplarily, a second flag bit may be pre-set, and the second flag bit may be used to indicate the scanning result of the terminal for the unconnected Bluetooth device, and the scanning result may include finding the unconnected Bluetooth device and not finding the unconnected Bluetooth device. The second flag bit may be preset with two values, namely a first value and a second value, the first value may indicate that the unconnected Bluetooth device is not found, and the second value may indicate that the unconnected Bluetooth device is found, for example, the first value is 0 and the second value is 1.
[0073] Before performing a Bluetooth scan, the second flag is preset to the first value. If one or more unconnected Bluetooth devices are found within the preset range of the terminal, the second flag is updated from the preset first value to the second value, indicating that an unconnected Bluetooth device is found nearby. If no unconnected Bluetooth device is found nearby, the second flag is always the first value. After the terminal finds an unconnected Bluetooth device nearby, the second flag can be updated to the second value.
[0074] After the second flag bit changes to the second value, the Bluetooth scanning function can be suspended and S203 can be executed. After the unconnected Bluetooth devices found are determined, if the unconnected Bluetooth devices found are not the target Bluetooth devices, the second flag bit is updated from the second value to the first value, and the Bluetooth scanning is restarted to obtain new unconnected Bluetooth devices. If it is determined that the unconnected Bluetooth device is the target Bluetooth device, the Bluetooth scanning function is turned off. That is, the Bluetooth scanning function can be turned on when the second flag bit is the first value, and the Bluetooth scanning function can be suspended when the second flag bit is the second value. The Bluetooth scanning function can also be turned on until the target Bluetooth device is found.
[0075] After a nearby unconnected Bluetooth device is found, the second flag is updated from the preset first value to the second value, and S203 is executed. When it is determined that the unconnected Bluetooth device is not the target Bluetooth device, the second flag is updated from the second value to the first value, and a nearby unconnected device is obtained again, and S202 is re-executed to realize the cyclic execution of the Bluetooth connection process.
[0076] In this embodiment, the method also includes: if the second flag bit is determined to be a preset first value according to a preset scanning cycle, it is determined that there are no unconnected Bluetooth devices within the preset range of the terminal, and a prompt message is sent to the user; wherein the prompt message is used to indicate that there are no unconnected Bluetooth devices within the preset range of the terminal.
[0077] Specifically, a scanning cycle can be preset, and the second flag bit is monitored according to the preset scanning cycle to determine whether the second flag bit is still the first value. For example, the terminal has not found any unconnected Bluetooth devices nearby, and the second flag bit is always the first value. Alternatively, the terminal finds that there are unconnected Bluetooth devices nearby, but none of them are target Bluetooth devices, and the second flag bit always changes from the first value to the second value and then to the first value. After a period of time, the second flag bit is still the first value.
[0078] If the second flag is determined to be the first value according to the scanning cycle, it can be considered that there is no unconnected Bluetooth device within the preset range of the terminal, and the Bluetooth connection cannot be completed. The terminal can send a prompt message to the user, prompting the user that there is no unconnected Bluetooth device within the preset range of the terminal. The user can change the range of the terminal or change the target Bluetooth device according to the prompt message.
[0079] The beneficial effect of such a setting is that by monitoring the second flag bit, it is possible to determine whether there is an unconnected Bluetooth device, thereby avoiding the terminal from performing Bluetooth scanning all the time, providing timely reminders to the user, and improving the efficiency of Bluetooth connection.
[0080] S203. If it is determined that the preset first flag bit is the preset initial value, the device identification of the unconnected Bluetooth device is determined, and the first flag bit is updated from the initial value to the preset target value; wherein the first flag bit is used to indicate the judgment state of the terminal for judging the two device identifications, the judgment state includes no judgment and judgment, the initial value of the first flag bit indicates that the judgment state of the terminal for judging the two device identifications is in a state of no judgment, and the target value of the first flag bit indicates that the judgment state of the terminal for judging the two device identifications is in a state of judgment.
[0081] Exemplarily, this step may refer to the above-mentioned step S103 and will not be described in detail.
[0082] S204: If it is determined that the device identification of the target Bluetooth device is consistent with the device identification of the unconnected Bluetooth device, the unconnected Bluetooth device is connected and the Bluetooth scanning function is turned off.
[0083] Exemplarily, this step may refer to the above-mentioned step S104 and will not be described in detail.
[0084] A method for Bluetooth connection provided by an embodiment of the present application determines the target Bluetooth device to be connected through user operation, and obtains the device identification of the target Bluetooth device. According to the Bluetooth scanning function of the terminal, it is determined whether there is an unconnected Bluetooth device within the preset range of the terminal. If it exists, it is determined whether the first flag is a preset initial value. If so, the device identification of the unconnected Bluetooth device is determined, the device identification of the target Bluetooth device is compared with the device identification of the unconnected Bluetooth device, and the first flag is updated from the initial value to the preset target value to avoid calling the Bluetooth connection interface again during the comparison process. If it is determined that the device identification of the target Bluetooth device is consistent with the device identification of the unconnected Bluetooth device, the unconnected Bluetooth device is connected, and the Bluetooth scanning function is turned off to avoid the terminal from continuing to scan and making repeated judgments. In the prior art, the SDK interface is called multiple times in the process of connecting a Bluetooth device, resulting in transmission delays, long calling interface duration, and other problems. Avoid multiple connections and feedback of multiple connection information, improve the efficiency and accuracy of Bluetooth connections, and enhance user experience.
[0085] Figure 3 This is a structural block diagram of a Bluetooth connection device provided in an embodiment of the present application, and the device is applied to a terminal. For ease of explanation, only the parts related to the embodiment of the present disclosure are shown. Figure 3 The device includes: a first determination module 301, a device scanning module 302, a second determination module 303 and a device connection module 304.
[0086] The first determination module 301 is used to determine the device identifier of the target Bluetooth device to be connected with the terminal in response to the Bluetooth device connection operation issued by the user through the visual interface of the terminal; wherein the device identifier is used to represent the Bluetooth device;
[0087] A device scanning module 302, configured to discover unconnected Bluetooth devices within a preset range of the terminal based on a Bluetooth scanning function of the terminal;
[0088] The second determination module 303 is used to determine the device identification of the unconnected Bluetooth device if it is determined that the preset first flag bit is a preset initial value, and update the first flag bit from the initial value to a preset target value; wherein the first flag bit is used to indicate the judgment state of the terminal for judging the two device identifications, the judgment state includes no judgment and judgment, the initial value of the first flag bit indicates that the judgment state of the terminal for judging the two device identifications is in a state of no judgment, and the target value of the first flag bit indicates that the judgment state of the terminal for judging the two device identifications is in a state of judgment;
[0089] The device connection module 304 is configured to connect the unconnected Bluetooth device and disable the Bluetooth scanning function if it is determined that the device identification of the target Bluetooth device is consistent with the device identification of the unconnected Bluetooth device.
[0090] Figure 4 A structural block diagram of a Bluetooth-connected device provided in an embodiment of the present application, wherein the data access record includes the data access frequency. Figure 3 Based on the embodiment shown, Figure 4 As shown, the first determination module 301 includes a target determination unit 3011 and an identification determination unit 3012 .
[0091] The target determination unit 3011 is used to determine any selected Bluetooth device as a target Bluetooth device to be connected with the terminal according to a connection operation issued by the user on the visual interface of the terminal to any selected Bluetooth device;
[0092] The identification determination unit 3012 is used to determine the device identification of the target Bluetooth device.
[0093] In one example, the device further includes:
[0094] A first flag monitoring module, configured to monitor the first flag according to a preset monitoring period after finding an unconnected Bluetooth device within a preset range of the terminal based on a Bluetooth scanning function of the terminal and if it is determined that the preset first flag is a preset target value;
[0095] The first flag bit updating module is used to determine the device identification of the unconnected Bluetooth device and update the first flag bit from the initial value to a preset target value if it is determined that the first flag bit is updated from the target value to the initial value.
[0096] In one example, the device further includes:
[0097] The first flag reset module is used to determine the device identification of the unconnected Bluetooth device and update the first flag from the initial value to a preset target value. If it is determined that the device identification of the target Bluetooth device is inconsistent with the device identification of the unconnected Bluetooth device, the first flag is updated from the target value to the preset initial value.
[0098] In one example, the device scanning module 302 is specifically configured to:
[0099] If at least one unconnected Bluetooth device is found within a preset range of the terminal based on the Bluetooth scanning function of the terminal, the preset second flag is updated from a preset first value to a second value; wherein the second flag is used to indicate the scanning result of the terminal for the unconnected Bluetooth device; the scanning result includes finding an unconnected Bluetooth device and not finding an unconnected Bluetooth device; the first value indicates that no unconnected Bluetooth device is found, and the second value indicates that an unconnected Bluetooth device is found.
[0100] In one example, the device further includes:
[0101] A prompt module is used to determine that there are no unconnected Bluetooth devices within the preset range of the terminal if the second flag bit is determined to be a preset first value according to a preset scanning cycle, and to send a prompt message to the user; wherein the prompt message is used to indicate that there are no unconnected Bluetooth devices within the preset range of the terminal.
[0102] Figure 5 A structural block diagram of an electronic device provided in an embodiment of the present application, such as Figure 5 As shown, the electronic device includes: a memory 51 and a processor 52; the memory 51 is a memory for storing instructions executable by the processor 52.
[0103] The processor 52 is configured to execute the method provided in the above embodiment.
[0104] The electronic device further includes a receiver 53 and a transmitter 54. The receiver 53 is used to receive instructions and data sent by other devices, and the transmitter 54 is used to send instructions and data to external devices.
[0105] Figure 6 It is a block diagram of an electronic device according to an exemplary embodiment, which device may be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, etc.
[0106] Device 600 may include one or more of the following components: a processing component 602 , a memory 604 , a power component 606 , a multimedia component 608 , an audio component 610 , an input / output (I / O) interface 612 , a sensor component 614 , and a communication component 616 .
[0107] The processing component 602 generally controls the overall operation of the device 600, such as operations associated with display, phone calls, data communications, camera operations, and recording operations. The processing component 602 may include one or more processors 620 to execute instructions to complete all or part of the steps of the above-mentioned method. In addition, the processing component 602 may include one or more modules to facilitate the interaction between the processing component 602 and other components. For example, the processing component 602 may include a multimedia module to facilitate the interaction between the multimedia component 608 and the processing component 602.
[0108] The memory 604 is configured to store various types of data to support operations on the device 600. Examples of such data include instructions for any application or method operating on the device 600, contact data, phone book data, messages, pictures, videos, etc. The memory 604 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
[0109] The power supply component 606 provides power to the various components of the device 600. The power supply component 606 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power for the device 600.
[0110] The multimedia component 608 includes a screen that provides an output interface between the device 600 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundaries of the touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 608 includes a front camera and / or a rear camera. When the device 600 is in an operating mode, such as a shooting mode or a video mode, the front camera and / or the rear camera may receive external multimedia data. Each front camera and the rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.
[0111] The audio component 610 is configured to output and / or input audio signals. For example, the audio component 610 includes a microphone (MIC), and when the device 600 is in an operating mode, such as a call mode, a recording mode, and a speech recognition mode, the microphone is configured to receive an external audio signal. The received audio signal can be further stored in the memory 604 or sent via the communication component 616. In some embodiments, the audio component 610 also includes a speaker for outputting audio signals.
[0112] I / O interface 612 provides an interface between processing component 602 and peripheral interface modules, such as keyboards, click wheels, buttons, etc. These buttons may include but are not limited to: a home button, a volume button, a start button, and a lock button.
[0113] The sensor assembly 614 includes one or more sensors for providing various aspects of status assessment for the device 600. For example, the sensor assembly 614 can detect the open / closed state of the device 600, the relative positioning of components, such as the display and keypad of the device 600, and the sensor assembly 614 can also detect the position change of the device 600 or a component of the device 600, the presence or absence of user contact with the device 600, the orientation or acceleration / deceleration of the device 600, and the temperature change of the device 600. The sensor assembly 614 may include a proximity sensor configured to detect the presence of nearby objects without any physical contact. The sensor assembly 614 may also include an optical sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 614 may also include an accelerometer, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
[0114] The communication component 616 is configured to facilitate wired or wireless communication between the device 600 and other devices. The device 600 can access a wireless network based on a communication standard, such as WiFi, 2G or 3G, or a combination thereof. In an exemplary embodiment, the communication component 616 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 616 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.
[0115] In an exemplary embodiment, the device 600 may be implemented by one or more application specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components to perform the above methods.
[0116] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 604 including instructions, and the instructions can be executed by a processor 620 of the device 600 to perform the above method. For example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.
[0117] A non-temporary computer-readable storage medium, when instructions in the storage medium are executed by a processor of a terminal device, enables the terminal device to execute the above-mentioned Bluetooth connection method of the terminal device.
[0118] The present application also discloses a computer program product, including a computer program, which implements the method described in this embodiment when executed by a processor.
[0119] Various embodiments of the systems and techniques described above in the present application can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include: being implemented in one or more computer programs, which can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor, which can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0120] The program code for implementing the method of the present application can be written in any combination of one or more programming languages. These program codes can be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code can be executed entirely on the machine, partially on the machine, partially on the machine as a stand-alone software package and partially on a remote machine, or entirely on a remote machine or electronic device.
[0121] In the context of the present application, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0122] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0123] The systems and techniques described herein can be implemented in a computing system that includes back-end components (e.g., as a data electronic device), or a computing system that includes middleware components (e.g., an application electronic device), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.
[0124] The computer system may include a client and an electronic device. The client and the electronic device are generally far away from each other and usually interact through a communication network. The relationship between the client and the electronic device is generated by computer programs running on corresponding computers and having a client-electronic device relationship with each other. The electronic device may be a cloud electronic device, also known as a cloud computing electronic device or a cloud host, which is a host product in a cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services ("Virtual Private Server", or "VPS" for short). The electronic device may also be an electronic device of a distributed system, or an electronic device combined with a blockchain. It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this application may be executed in parallel, sequentially, or in different orders, as long as the desired results of the technical solution disclosed in this application can be achieved, and this document is not limited here.
[0125] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary techniques in the art that are not disclosed in the present application. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the following claims.
[0126] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.
Claims
1. A Bluetooth connection method, characterized in that: The method is applied to a terminal, and the method includes: In response to a Bluetooth device connection operation issued by a user through a visual interface of a terminal, determining a device identifier of a target Bluetooth device to be connected to the terminal; wherein the device identifier is used to represent a Bluetooth device; Based on the Bluetooth scanning function of the terminal, discovering unconnected Bluetooth devices within a preset range of the terminal; If it is determined that the preset first flag bit is a preset initial value, the device identification of the unconnected Bluetooth device is determined, and the first flag bit is updated from the initial value to a preset target value; wherein the first flag bit is used to indicate the judgment state of the terminal for judging the two device identifications, the judgment state includes no judgment and judgment, the initial value of the first flag bit indicates that the judgment state of the terminal for judging the two device identifications is in a state of no judgment, and the target value of the first flag bit indicates that the judgment state of the terminal for judging the two device identifications is in a state of judgment; If it is determined that the device identification of the target Bluetooth device is consistent with the device identification of the unconnected Bluetooth device, the unconnected Bluetooth device is connected and the Bluetooth scanning function is turned off.
2. The method according to claim 1, characterized in that In response to a Bluetooth device connection operation issued by a user through a visual interface of a terminal, determining a device identifier of a target Bluetooth device to be connected to the terminal includes: According to a connection operation issued by a user on a visual interface of a terminal to any selected Bluetooth device, determining the selected Bluetooth device as a target Bluetooth device to be connected with the terminal; Determine the device identification of the target Bluetooth device.
3. The method according to claim 1, characterized in that After an unconnected Bluetooth device is found within a preset range of the terminal based on the Bluetooth scanning function of the terminal, the method further includes: If it is determined that the preset first flag bit is the preset target value, monitoring the first flag bit according to a preset monitoring period; If it is determined that the first flag bit is updated from the target value to the initial value, the device identifier of the unconnected Bluetooth device is determined, and the first flag bit is updated from the initial value to a preset target value.
4. The method according to claim 1, characterized in that After determining the device identification of the unconnected Bluetooth device and updating the first flag bit from the initial value to a preset target value, the method further includes: If it is determined that the device identification of the target Bluetooth device is inconsistent with the device identification of the unconnected Bluetooth device, the first flag bit is updated from the target value to a preset initial value.
5. The method according to claim 1, characterized in that Based on the Bluetooth scanning function of the terminal, an unconnected Bluetooth device is discovered within a preset range of the terminal, including: If at least one unconnected Bluetooth device is found within a preset range of the terminal based on the Bluetooth scanning function of the terminal, the preset second flag is updated from a preset first value to a second value; wherein the second flag is used to indicate the scanning result of the terminal for the unconnected Bluetooth device; the scanning result includes finding an unconnected Bluetooth device and not finding an unconnected Bluetooth device; the first value indicates that no unconnected Bluetooth device is found, and the second value indicates that an unconnected Bluetooth device is found.
6. The method according to claim 5, characterized in that The method further comprises: If, according to the preset scanning cycle, it is determined that the second flag bit is a preset first value, it is determined that there are no unconnected Bluetooth devices within the preset range of the terminal, and a prompt message is sent to the user; wherein the prompt message is used to indicate that there are no unconnected Bluetooth devices within the preset range of the terminal.
7. A Bluetooth-connected device, characterized in that: The device is applied to a terminal, and the device includes: A first determination module, configured to determine a device identifier of a target Bluetooth device to be connected to the terminal in response to a Bluetooth device connection operation issued by a user through a visual interface of the terminal; wherein the device identifier is used to represent the Bluetooth device; A device scanning module, used to find unconnected Bluetooth devices within a preset range of the terminal based on the Bluetooth scanning function of the terminal; A second determination module is used to determine the device identification of the unconnected Bluetooth device if it is determined that the preset first flag bit is a preset initial value, and update the first flag bit from the initial value to a preset target value; wherein the first flag bit is used to indicate the judgment state of the terminal for judging the two device identifications, the judgment state includes no judgment and judgment, the initial value of the first flag bit indicates that the judgment state of the terminal for judging the two device identifications is in a state of no judgment, and the target value of the first flag bit indicates that the judgment state of the terminal for judging the two device identifications is in a state of judgment; The device connection module is used to connect the unconnected Bluetooth device and disable the Bluetooth scanning function if it is determined that the device identification of the target Bluetooth device is consistent with the device identification of the unconnected Bluetooth device.
8. An electronic device, characterized in that: include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the Bluetooth connection method according to any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are executed by a processor, they are used to implement the Bluetooth connection method according to any one of claims 1 to 6.
10. A computer program product, characterized in that The invention comprises a computer program, which, when executed by a processor, implements the Bluetooth connection method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Indoor positioning method, device and equipment based on WiFi
CN114501315A
Projection, control and management of user device applications using connection resources
CN114868106A