CN107770762B - Method and device for establishing Bluetooth connection - Google Patents

Method and device for establishing Bluetooth connection Download PDF

Info

Publication number
CN107770762B
CN107770762B CN201711157271.8A CN201711157271A CN107770762B CN 107770762 B CN107770762 B CN 107770762B CN 201711157271 A CN201711157271 A CN 201711157271A CN 107770762 B CN107770762 B CN 107770762B
Authority
CN
China
Prior art keywords
bluetooth device
identifier
module
target
bluetooth
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201711157271.8A
Other languages
Chinese (zh)
Other versions
CN107770762A (en
Inventor
陆舟
于华章
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Feitian Technologies Co Ltd
Original Assignee
Feitian Technologies Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Feitian Technologies Co Ltd filed Critical Feitian Technologies Co Ltd
Priority to CN201711157271.8A priority Critical patent/CN107770762B/en
Publication of CN107770762A publication Critical patent/CN107770762A/en
Application granted granted Critical
Publication of CN107770762B publication Critical patent/CN107770762B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Mobile Radio Communication Systems (AREA)

Abstract

The invention relates to the field of communication, in particular to a method and a device for establishing Bluetooth connection, wherein the method comprises the following steps: the application program acquires an identifier of the target Bluetooth device; acquiring paired Bluetooth equipment information from an operating system, and establishing connection and communication with target Bluetooth equipment when the paired Bluetooth equipment information contains Bluetooth equipment information matched with the identifier of the target Bluetooth equipment; when the paired Bluetooth device information does not contain Bluetooth device information matched with the identifier of the target Bluetooth device, scanning surrounding Bluetooth devices, and when the Bluetooth device information of the Bluetooth device is matched with the identifier of the target Bluetooth device, establishing connection and communication with the target Bluetooth device; the invention ensures that the operation in the application program is not influenced by the Bluetooth connection of the user through the operating system in advance.

Description

Method and device for establishing Bluetooth connection
Technical Field
The present invention relates to the field of communications, and in particular, to a method and an apparatus for establishing a bluetooth connection.
Background
Bluetooth is a radio technology supporting short-distance communication between devices, and due to the advantages of a large transmission range, strong anti-interference performance and the like of the bluetooth technology, the bluetooth function has become a standard configuration function of a mobile terminal such as a smart phone.
In the prior art, an application program of a mobile device already has a scanning connection function for a bluetooth device; when the user uses the application program, the user is used to scan and connect the Bluetooth device in the operating system of the mobile device, and then returns to the application program to perform operations related to the Bluetooth device; since the bluetooth device may have already been paired with the terminal device, the application may not scan or connect the bluetooth device.
Disclosure of Invention
In order to solve the technical defects in the prior art, the invention provides a method and a device for establishing Bluetooth connection.
The invention provides a method for establishing Bluetooth connection, which comprises the following steps:
step S1, the application program acquires the identifier of the target Bluetooth device;
step S2, the application program obtains the paired Bluetooth device information from the operating system, and judges whether the paired Bluetooth device information has the Bluetooth device information matched with the identifier of the target Bluetooth device, if yes, step S4 is executed, otherwise, the surrounding Bluetooth devices are scanned, and when the Bluetooth devices are scanned, step S3 is executed;
step S3, the application program acquires the Bluetooth device information of the scanned Bluetooth device, and judges whether the acquired Bluetooth device information is matched with the identifier of the target Bluetooth device, if so, the scanning is stopped, and the step S4 is executed, otherwise, the error report is finished;
and step S4, the application program establishes connection and communication with the target Bluetooth device according to the Bluetooth device information matched with the identifier of the target Bluetooth device, and the operation is finished.
The invention provides a device for establishing Bluetooth connection, which comprises:
the first acquisition module is used for acquiring the identifier of the target Bluetooth device;
the second acquisition module is used for acquiring the paired Bluetooth equipment information from the operating system;
the first judging module is used for judging whether the paired Bluetooth device information acquired by the second acquiring module contains Bluetooth device information matched with the identifier of the target Bluetooth device acquired by the first acquiring module;
the communication module is used for establishing connection and communication with the target Bluetooth equipment according to the Bluetooth equipment information matched with the identifier of the target Bluetooth equipment when the first judgment module judges that the paired Bluetooth equipment information contains the Bluetooth equipment information matched with the identifier of the target Bluetooth equipment, and ending the connection;
the scanning module is used for scanning the peripheral Bluetooth equipment when the first judging module judges that the paired Bluetooth equipment information does not have Bluetooth equipment information matched with the identifier of the target Bluetooth equipment;
the third acquisition module is used for acquiring the Bluetooth equipment information of the scanned Bluetooth equipment when the scanning module scans the Bluetooth equipment;
the second judging module is used for judging whether the Bluetooth device information of the Bluetooth device acquired by the third acquiring module is matched with the identifier of the target Bluetooth device acquired by the first acquiring module;
the second judging module is used for judging whether the Bluetooth equipment information is matched with the identifier of the target Bluetooth equipment or not;
the scanning stopping module is used for stopping scanning when the second judging module judges that the Bluetooth device information is matched with the identifier of the target Bluetooth device;
and the communication module is also used for establishing connection and communication with the target Bluetooth device according to the Bluetooth device information matched with the identifier of the target Bluetooth device when the second judging module judges that the Bluetooth device information is matched with the identifier of the target Bluetooth device, and ending the connection.
The beneficial effects achieved by adopting the technical scheme are as follows: the terminal device adds operations such as detection and judgment of pairing information in the operating system before connecting the Bluetooth device, so that the operation performed in the application program is not influenced by the fact that a user performs Bluetooth connection through the operating system in advance.
Drawings
Fig. 1 is a flowchart of a method for establishing a bluetooth connection according to embodiment 1 of the present invention;
fig. 2 is a flowchart of a method for establishing a bluetooth connection according to embodiment 2 of the present invention;
fig. 3 is a block diagram of an apparatus for establishing a bluetooth connection according to embodiment 3 of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, embodiments of the present invention will be described in detail with reference to the accompanying drawings.
Example 1
The embodiment provides a method for establishing a bluetooth connection, which is applied to a mobile terminal of an Android operating system, and with reference to fig. 1, the method includes:
step 101, detecting whether the Bluetooth is started or not by an application program, if so, executing step 103, otherwise, executing step 102;
specifically, the application program calls a system interface function bluetooth adapter, get default address (), isEnabled (), judges whether the return value for calling the function is true, if yes, the application program judges that the bluetooth is opened, and executes step 103, otherwise, the application program judges that the bluetooth is not opened, and executes step 102.
Step 102, starting Bluetooth by an application program;
specifically, the application program firstly creates a starting event requesting to start the bluetooth, and judges whether the bluetooth module is started successfully by calling a callback function, if the bluetooth module is started successfully, the step 103 is continuously executed, otherwise, the bluetooth module is started unsuccessfully, and error reporting is finished;
the specific implementation of the start event for creating the request to start the bluetooth is as follows: new Intent (bluetooth adapter. action _ REQUEST _ ENABLE);
startActivityForResult(intent,CODE_TURN_ON_BT);
the method comprises the steps that intent is an event starting object of an Android system, a startActivityForResult function is an interface function which transmits a request back to the Android system, and CODE _ TURN _ ON _ BT is a request mark used for expressing the request back to the Android system;
the specific steps of calling a callback function to judge whether the Bluetooth module is successfully started are as follows: reloading an onactive result (int request code, int result code, int data) function under Activity, judging a return value result code obtained by reloading the function, if the result code is equal to Activity.
103, the application program acquires an identifier of the target Bluetooth device;
the identifier of the target bluetooth device may be: a serial number of the target bluetooth device or a name of the target bluetooth device or other data that can identify the bluetooth device;
specifically, the application program acquires a prestored identifier of the target Bluetooth device;
in more detail, the application program acquires a pre-stored serial number of the target bluetooth device, and converts the serial number of the target bluetooth device into a name of the target bluetooth device according to a preset rule, wherein the name of the bluetooth device is an identifier of the target bluetooth device;
for example, in this embodiment, the serial number of the target bluetooth device acquired by the application is: 650230000000173, deleting the first three digits of the serial number by the application program, and splicing the serial number with a preset character string FT _ to obtain the name FT _230000000173 of the target Bluetooth equipment;
optionally, the application program receives an identifier of the target bluetooth device input by the user;
in more detail, the application program receives a serial number of the target bluetooth device input by a user, and converts the serial number of the target bluetooth device into a name of the target bluetooth device according to a preset rule, wherein the name of the bluetooth device is an identifier of the target bluetooth device;
optionally, the application program receives login information input by the user, and acquires an identifier of the target bluetooth device, which is matched with the login information input by the user, from the server;
step 104, the application program judges whether the paired bluetooth equipment information can be acquired in the operating system, if so, step 105 is executed, otherwise, step 107 is executed;
it should be noted that each piece of paired bluetooth device information at least includes an identifier of a bluetooth device and a MAC address of the bluetooth device;
specifically, the application calls a system function bluetooth adapter. And receiving data returned by the calling function, judging that the paired Bluetooth device information can be acquired in the operating system by the application program when the return is not empty, and judging that the paired Bluetooth device information is not acquired in the operating system by the application program when the return is empty.
In the embodiment, the returned data received by the application program are [ ABC _1000000028(CE: EB:0C:37: DF:5F), BK _ FT1067(F3:24: E2:8A:2F:47), FT _230000000173(C4:5D:37:6B: F9:9F) ]; in this embodiment, the specific steps for the application to obtain the three pieces of bluetooth device information are as follows:
bluetooth device identifier MAC address of Bluetooth device
1 ABC_1000000028 CE:EB:0C:37:DF:5F
2 BK_FT1067 F3:24:E2:8A:2F:47
3 FT_230000000173 C4:5D:37:6B:F9:9F
Step 105, the application program judges whether the paired Bluetooth device information in the operating system has Bluetooth device information matched with the identifier of the target Bluetooth device, if so, step 106 is executed, otherwise, step 107 is executed;
specifically, the application program searches the bluetooth device information including the identifier of the target bluetooth device in the paired bluetooth device information according to the identifier of the target bluetooth device, if the bluetooth device information is found, step 106 is executed, and if the bluetooth device information is not found, step 107 is executed;
for example, in this embodiment, the bluetooth device information found according to the identifier FT _230000000173 of the target bluetooth device is the third bluetooth device in the above list.
106, deleting the Bluetooth equipment information matched with the identifier of the target Bluetooth equipment in the paired Bluetooth equipment information in the operating system by the application program;
the application program obtains a removeBond () method through a getClass (). getMethod ("removeBond", (Class [ ]) null) method according to a reflection mode, the removeBond () method is executed, namely the Bluetooth device information matched with the identifier of the target Bluetooth device in the paired Bluetooth device information in the operating system can be deleted, if the return value of the function is true, the deletion is successful, and if the return value of the function is flash, the deletion is failed.
Step 107, the application program scans the surrounding equipment; when the bluetooth device is scanned, step 108 is executed;
specifically, the application program calls a getSystemService (context.bluetooth _ SERVICE) method of the current context, getaddress (). startLenScan (mcleescan call) to start the operation of the scanning device, and returns the scanning result through the mcleescan call-back; the scanning result is an object of the Bluetooth device type, and the scanning result is the scanned Bluetooth device information of the Bluetooth device;
step 108, the application program acquires the Bluetooth equipment information of the scanned Bluetooth equipment, and judges whether the scanned Bluetooth equipment information is matched with the identifier of the target Bluetooth equipment, if so, step 109 is executed, otherwise, step 107 is returned;
specifically, the bluetooth device information at least includes an identifier of the bluetooth device and a MAC address of the bluetooth device, and in this embodiment, the bluetooth device information acquired by the application program specifically includes a name of the bluetooth device and a MAC address of the bluetooth device.
For example, when the scanning result is [ FT _230000000173(C4:5D:37:6B: F9:9F) ], the scanned Bluetooth device information is judged to be matched with the identifier of the target Bluetooth device, otherwise, the scanned Bluetooth device information is judged to be not matched with the identifier of the target Bluetooth device;
preferably, step 107 is preceded by: setting an initial value of scanning time by an application program;
correspondingly, the step 108 of determining whether the bluetooth device information of the scanned bluetooth device does not match the identifier of the target bluetooth device by the application further includes: the application program judges whether the scanning time exceeds the preset time, if so, the scanning is stopped, and if not, the step 107 is returned;
step 109, the application program stops scanning, acquires the MAC address of the target Bluetooth device from the scanned Bluetooth device information, and sends a connection request to the target Bluetooth device according to the MAC address of the target Bluetooth device;
specifically, the application calls the getsysteservice (context.bluetooth _ SERVICE) method of the current context, getdatapt (). stopLenScan (mcleescan call) to stop the operation of the scanning device.
Step 110, the application program judges whether the connection is successful; if yes, go to step 111; otherwise, error reporting is finished;
specifically, the application program calls the connectictgatt () method to start connection, returns the connection state through the mcattcallback, and succeeds when the returned status is bluetooth gatt.
Preferably, step 110 further comprises: the application program sets an initial value of the connection request times; step 110 is followed by: updating the number of times of sending the connection request by the application program;
correspondingly, step 110 specifically includes: when judging the connection failure, the method further comprises the following steps: the application program judges whether the connection times are larger than a preset value, if so, the connection fails, and if not, the step 110 is returned;
step 111, the application program communicates with the target bluetooth device.
Preferably, step 109 further includes: the application program stores the scanned Bluetooth equipment information;
correspondingly, the steps 103 and 104 further include: the application program judges whether the Bluetooth device information matched with the identifier of the target Bluetooth device exists in the Bluetooth device information stored by the application program, if so, the application program acquires the MAC address of the target Bluetooth device from the Bluetooth device information matched with the target Bluetooth device information, sends a connection request to the target Bluetooth device according to the MAC address of the target Bluetooth device, and executes the step 110; otherwise step 104 is performed.
Example 2
The present embodiment provides a method for establishing a bluetooth connection, referring to fig. 2, including:
step 201, the application program checks whether the Bluetooth is started, if so, step 203 is executed, otherwise, step 202 is executed;
specifically, the application program calls a system interface function bluetooth adapter, get default address (), isEnabled (), and determines whether the return value for calling the function is true, if yes, the application program determines that the bluetooth module is already started, step 203 is executed, otherwise, the application program determines that the bluetooth module is not started, and step 202 is executed.
Step 202, starting Bluetooth by an application program;
specifically, the application program firstly creates a starting event requesting to start the bluetooth, displays and judges whether the bluetooth module is started successfully by calling a callback function, if the bluetooth module is started successfully, the step 203 is continuously executed, otherwise, the bluetooth module is started unsuccessfully, and error reporting is finished;
the specific implementation of the start event for creating the request to start the bluetooth is as follows: recent interest (bluetooth adapter. action _ REQUEST _ ENABLE);
startActivityForResult(intent,CODE_TURN_ON_BT);
the method comprises the steps that intent is an event starting object of an Android system, a startActivityForResult function is an interface function which transmits a request back to the Android system, and CODE _ TURN _ ON _ BT is a request mark used for expressing the request back to the Android system;
the specific steps of calling a callback function to judge whether the Bluetooth module is successfully started are as follows: reloading an onactive result (int requestCode, int resultCode, Intentdata) function under Activity, judging a return value resultCode obtained by reloading the function, if the resultCode is equal to Activity.
Step 203, the application program acquires the identifier of the target Bluetooth device;
the identifier of the target bluetooth device may be: a serial number of the target bluetooth device or a name of the target bluetooth device or other data that can identify the bluetooth device;
specifically, the application program acquires a prestored identifier of the target Bluetooth device;
in more detail, the application program acquires a pre-stored serial number of the target bluetooth device, and converts the serial number of the target bluetooth device into a name of the target bluetooth device according to a preset rule, wherein the name of the bluetooth device is an identifier of the target bluetooth device;
for example, in this embodiment, the serial number of the target bluetooth device acquired by the application is: 650230000000173, deleting the first three digits of the serial number by the application program, and splicing the serial number with a preset character string FT _ to obtain the name FT _230000000173 of the target Bluetooth equipment;
optionally, the application program receives an identifier of the target bluetooth device input by the user;
in more detail, the application program receives a serial number of the target bluetooth device input by a user, and converts the serial number of the target bluetooth device into a name of the target bluetooth device according to a preset rule, wherein the name of the bluetooth device is an identifier of the target bluetooth device;
optionally, the application program receives login information input by the user, and acquires an identifier of the target bluetooth device, which is matched with the login information input by the user, from the server;
step 204, the application program judges whether the paired bluetooth device information can be acquired in the operating system, if so, step 205 is executed, otherwise, step 207 is executed;
specifically, the application calls a system function bluetooth adapter. And receiving data returned by the calling function, judging that the paired Bluetooth device information can be acquired in the operating system by the application program when the return is not empty, and judging that the paired Bluetooth device information is not acquired in the operating system by the application program when the return is empty.
It should be noted that each piece of paired bluetooth device information at least includes a bluetooth device identifier and a MAC address of a bluetooth device;
in the embodiment, the returned data received by the application program are [ ABC _1000000028(CE: EB:0C:37: DF:5F), BK _ FT1067(F3:24: E2:8A:2F:47), FT _230000000173(C4:5D:37:6B: F9:9F) ]; in this embodiment, the specific steps for the application to obtain the three pieces of bluetooth device information are as follows:
for example, the paired bluetooth device information acquired by the application program is specifically:
name of Bluetooth device MAC address of Bluetooth device
1 ABC_1000000028 CE:EB:0C:37:DF:5F
2 BK_FT1067 F3:24:E2:8A:2F:47
3 FT_230000000173 C4:5D:37:6B:F9:9F
Step 205, the application program judges whether the paired bluetooth device information has bluetooth device information matched with the identifier of the target bluetooth device, if yes, step 206 is executed, otherwise, step 207 is executed;
step 206, the application program acquires the MAC address of the target Bluetooth device from the Bluetooth device information matched with the identifier of the target Bluetooth device; step 210 is executed;
step 207, the application program scans the peripheral Bluetooth equipment; when the bluetooth device is scanned, step 208 is executed;
specifically, the application program calls a getSystemService (context.bluetooth _ SERVICE) method of the current context, getaddress (). startLenScan (mcleescan call) to start the operation of the scanning device, returns the scanning result through the mcleescan call callback, and executes step 208 when returning true indicates that the scanning operation is successfully performed;
step 208, the application program acquires the scanned Bluetooth equipment information; judging whether the scanned Bluetooth device information of the Bluetooth device is matched with the identifier of the target Bluetooth device, if so, executing a step 209, otherwise, returning to the step 207;
preferably, step 207 further comprises: setting an initial value of scanning time by an application program;
accordingly, the step 208 of determining whether the bluetooth device information of the scanned bluetooth device does not match the identifier of the target bluetooth device by the application further includes: the application program judges whether the scanning time exceeds the preset time, if so, the scanning is stopped, and if not, the step 207 is returned to;
step 209, the application stops scanning; acquiring the MAC address of the target Bluetooth device from the Bluetooth device information matched with the identifier of the target Bluetooth device;
specifically, the application calls the getsysteservice (context.bluetooth _ SERVICE) method of the current context, getdatapt (). stopLenScan (mcleescan call) to stop the operation of the scanning device.
Step 210, the application program initiates a connection request to the target bluetooth device according to the MAC address of the target bluetooth device;
step 211, the application program determines whether the connection is successful, if so, step 212 is executed, otherwise, the error is reported to be finished;
specifically, the application program calls the connectictgatt () method to start connection, returns the connection state through the mcattcallback, and succeeds when the returned status is bluetooth gatt.
Preferably, step 211 further comprises: the application program sets an initial value of the connection request times; step 211 is followed by: updating the number of times of sending the connection request by the application program;
correspondingly, step 211 specifically includes: when judging the connection failure, the method further comprises the following steps: the application program judges whether the connection times are larger than a preset value, if so, the connection fails, and if not, the step 211 is returned to;
step 212, the application communicates with the target bluetooth device.
Preferably, step 209 further comprises: the application program stores the scanned Bluetooth equipment information;
correspondingly, the steps 203 and 204 further include: the application program judges whether the Bluetooth device information matched with the identifier of the target Bluetooth device exists in the Bluetooth device information stored by the application program, if so, the application program acquires the MAC address of the target Bluetooth device from the Bluetooth device information matched with the target Bluetooth device information, sends a connection request to the target Bluetooth device according to the MAC address of the target Bluetooth device, and executes step 211; otherwise, step 204 is performed.
Example 3
The present embodiment provides an apparatus for establishing a bluetooth connection, as shown in fig. 3, including:
a first obtaining module 11, configured to obtain an identifier of a target bluetooth device;
optionally, the first obtaining module 11 is specifically configured to obtain an identifier of a target bluetooth device, which is pre-stored or input by a user.
Optionally, the first obtaining module 11 is specifically configured to obtain, from the server, an identifier of the target bluetooth device matched with the login information according to the login information input by the user.
A second obtaining module 12, configured to obtain paired bluetooth device information from an operating system;
the first judging module 13 is configured to judge whether there is bluetooth device information that matches the identifier of the target bluetooth device acquired by the first acquiring module 11 in the paired bluetooth device information acquired by the second acquiring module 12;
the communication module 14 is configured to establish connection and communication with the target bluetooth device according to the bluetooth device information matched with the identifier of the target bluetooth device when the first determining module 13 determines that the paired bluetooth device information includes the bluetooth device information matched with the identifier of the target bluetooth device, and then the connection and communication is completed;
specifically, the communication module 14 is specifically configured to, when the first determining module 13 determines that there is bluetooth device information that matches the identifier of the target bluetooth device in the paired bluetooth device information, obtain an MAC address from the bluetooth device information that matches the identifier of the target bluetooth device, send a connection request to the target bluetooth device according to the MAC address, and when the connection is successful, perform communication, and then end;
the scanning module 15 is configured to scan the peripheral bluetooth devices when the first determining module 13 determines that there is no bluetooth device information matching the identifier of the target bluetooth device in the paired bluetooth device information;
a third obtaining module 16, configured to obtain bluetooth device information of the scanned bluetooth device when the scanning module 15 scans the bluetooth device;
a second judging module 17, configured to judge whether the bluetooth device information of the bluetooth device acquired by the third acquiring module 16 matches the identifier of the target bluetooth device acquired by the first acquiring module 11;
an ending module 18, configured to end error reporting when the second determining module 17 determines that the bluetooth device information does not match the identifier of the target bluetooth device;
a scanning stopping module 19 for stopping scanning when the second judging module 17 judges that the bluetooth device information matches the identifier of the target bluetooth device;
the communication module 14 is further configured to, when the second determination module 17 determines that the bluetooth device information matches the identifier of the target bluetooth device, establish connection and communication with the target bluetooth device according to the bluetooth device information matching the identifier of the target bluetooth device, and then end.
Specifically, the communication module 14 is specifically configured to, when the second determination module determines that the bluetooth device information matches the identifier of the target bluetooth device, obtain the MAC address from the bluetooth device information that matches the identifier of the target bluetooth device, send a connection request to the target bluetooth device according to the MAC address, and perform communication after the connection is successful, thereby ending the process.
Preferably, the apparatus further comprises: a deletion module;
the deletion module specifically includes: a deleting unit, a scanning unit and a judging unit;
a deleting unit, configured to delete the bluetooth device information that matches the identifier of the target bluetooth device from the operating system when the first determining module 13 determines that there is bluetooth device information that matches the identifier of the target bluetooth device in the paired bluetooth device information; triggering a scanning unit;
a scanning unit for scanning surrounding Bluetooth devices;
a judging unit, configured to, when the scanning unit scans a bluetooth device, acquire bluetooth device information of the scanned bluetooth device, and judge whether the acquired bluetooth device information matches with an identifier of a target bluetooth device acquired by the first acquiring module 11;
correspondingly, the communication module 14 is configured to establish connection and communication with the target bluetooth device according to the bluetooth device information matched with the target bluetooth device when the judgment unit judges that the acquired bluetooth device information matches with the identifier of the target bluetooth device, and then end; and is further configured to establish connection and communication with the target bluetooth device according to the bluetooth device information matched with the identifier of the target bluetooth device when the second determining module 17 determines that the bluetooth device information matches with the identifier of the target bluetooth device, and then end.
Preferably, the apparatus further comprises: detecting a module and starting a Bluetooth module;
the detection module is used for checking whether the Bluetooth is started or not;
the starting Bluetooth module is used for starting Bluetooth when the detection module does not start Bluetooth;
correspondingly, the first obtaining module 11 is configured to obtain an identifier of the target bluetooth device when the detecting module detects that bluetooth has been turned on; and the Bluetooth module is also used for acquiring the identifier of the target Bluetooth device after the Bluetooth module is started to start Bluetooth.
Preferably, the apparatus further comprises: a setting module and a third judging module;
the setting module is used for setting an initial value of the scanning time;
a third judging module, configured to judge whether the scanning time exceeds a preset time when the second judging module 17 judges that the bluetooth device information does not match the identifier of the target bluetooth device;
correspondingly, the ending module 18 is further configured to end when the third determining module determines that the scanning time exceeds the preset time;
the scanning module 15 is further configured to scan the peripheral bluetooth devices when the third determining module determines that the scanning time does not exceed the preset time.
Preferably, the apparatus further comprises: the storage module and the fourth judgment module;
the storage module is configured to store and acquire the bluetooth device information after the second determination module 17 determines that the acquired bluetooth device information matches the identifier of the target bluetooth device;
a fourth judging module, configured to acquire the stored bluetooth device information from the storage module, and judge whether there is bluetooth device information in the acquired bluetooth device information that matches the identifier of the target bluetooth device acquired by the first acquiring module 11;
correspondingly, the second obtaining module 12 is specifically configured to obtain paired bluetooth device information from the operating system when the fourth determining module determines that there is no bluetooth device information that matches the identifier of the target bluetooth device in the obtained bluetooth device information;
the communication module 14 is further configured to, when the fourth determining module determines that the acquired bluetooth device information includes bluetooth device information that matches the identifier of the target bluetooth device, establish connection and communication with the target bluetooth device according to the bluetooth device information that matches the identifier of the target bluetooth device, and then end.
It should be noted that the bluetooth device information specifically includes: an identifier of the bluetooth device and a MAC address of the bluetooth device; the bluetooth device information matched with the identifier of the target bluetooth device specifically includes: an identifier of the target bluetooth device and a MAC address of the target bluetooth device; the identifier of the target bluetooth device is specifically the name of the target bluetooth device or the serial number of the target bluetooth device.
The above description is only for the preferred embodiment of the present invention, but the scope of the present invention is not limited thereto, and any changes or substitutions that can be easily conceived by those skilled in the art within the technical scope of the present invention are included in the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

Claims (15)

1. A method of establishing a bluetooth connection, comprising:
step S1, the application program acquires the identifier of the target Bluetooth device;
step S2, the application program obtains the paired Bluetooth device information from the operating system, and judges whether the paired Bluetooth device information has the Bluetooth device information matched with the identifier of the target Bluetooth device, if yes, step S4 is executed, otherwise, the surrounding Bluetooth devices are scanned, and when the Bluetooth devices are scanned, step S3 is executed;
step S3, the application program obtains the Bluetooth device information of the scanned Bluetooth device, and judges whether the obtained Bluetooth device information is matched with the identifier of the target Bluetooth device, if yes, the scanning is stopped, and step S4 is executed, otherwise, the error report is finished;
step S4, the application program establishes connection and communication with the target Bluetooth device according to the Bluetooth device information matched with the identifier of the target Bluetooth device, and the operation is finished;
in the step S2, after the application program determines that there is bluetooth device information matching the identifier of the target bluetooth device in the paired bluetooth device information, the method further includes, before executing step S4:
step 101, the application program deletes the Bluetooth device information matched with the identifier of the target Bluetooth device from the operating system, scans the surrounding Bluetooth devices, and executes step 102 when the Bluetooth devices are scanned;
and 102, the application program acquires the scanned Bluetooth device information of the Bluetooth device, judges whether the acquired Bluetooth device information is matched with the identifier of the target Bluetooth device, stops scanning if the acquired Bluetooth device information is matched with the identifier of the target Bluetooth device, and continues to execute the step S4, otherwise, the error report is finished.
2. The method of claim 1, wherein the step S1 is preceded by: the application checks whether bluetooth has been turned on, if so, performs step S1, otherwise, turns on bluetooth, performs step S1.
3. The method of claim 1, wherein the bluetooth device information specifically comprises: an identifier of the bluetooth device and a MAC address of the bluetooth device; the bluetooth device information matched with the identifier of the target bluetooth device specifically includes: an identifier of the target bluetooth device and a MAC address of the target bluetooth device; the identifier of the target bluetooth device is specifically a name of the target bluetooth device or a serial number of the target bluetooth device.
4. The method according to claim 1, wherein the step S1 specifically includes: the application program obtains the identifier of the target bluetooth device, which is either pre-stored or entered by the user.
5. The method according to claim 1, wherein the step S1 specifically includes: and the application program acquires the identifier of the target Bluetooth equipment matched with the login information from the server according to the login information input by the user.
6. The method of claim 1, wherein said scanning for surrounding bluetooth devices further comprises, prior to: setting an initial value of scanning time by an application program;
in step S3, when the application program determines that the acquired bluetooth device information does not match the identifier of the target bluetooth device, it determines whether the scanning time exceeds a preset time, if so, the scanning is ended, otherwise, the application program continues to scan the surrounding bluetooth devices.
7. The method according to claim 1, wherein the step S4 is specifically: and the application program acquires the MAC address from the Bluetooth equipment information matched with the identifier of the target Bluetooth equipment, sends a connection request to the target Bluetooth equipment according to the MAC address, and finishes communication after connection is successful.
8. The method according to claim 1, wherein in step S3, after the application program determines that the acquired bluetooth device information matches the identifier of the target bluetooth device, the method further comprises: the application program stores the acquired Bluetooth equipment information;
after the step S1, the step S2 is preceded by: and the application program judges whether the Bluetooth device information matched with the identifier of the target Bluetooth device exists in the Bluetooth device information stored by the application program, if so, the step S4 is executed, and if not, the step S2 is executed.
9. An apparatus for establishing a bluetooth connection, comprising:
the first acquisition module is used for acquiring the identifier of the target Bluetooth device;
the second acquisition module is used for acquiring the paired Bluetooth equipment information from the operating system;
the first judging module is used for judging whether the paired Bluetooth device information acquired by the second acquiring module contains Bluetooth device information matched with the identifier of the target Bluetooth device acquired by the first acquiring module;
the communication module is used for establishing connection and communication with a target Bluetooth device according to the Bluetooth device information matched with the identifier of the target Bluetooth device when the first judgment module judges that the paired Bluetooth device information contains the Bluetooth device information matched with the identifier of the target Bluetooth device, and ending the connection;
the scanning module is used for scanning the peripheral Bluetooth equipment when the first judging module judges that the paired Bluetooth equipment information does not have Bluetooth equipment information matched with the identifier of the target Bluetooth equipment;
the third acquisition module is used for acquiring the Bluetooth equipment information of the scanned Bluetooth equipment when the scanning module scans the Bluetooth equipment;
the second judging module is used for judging whether the Bluetooth device information of the Bluetooth device acquired by the third acquiring module is matched with the identifier of the target Bluetooth device acquired by the first acquiring module;
an end module, configured to end an error report when the second determination module determines that the bluetooth device information does not match the identifier of the target bluetooth device;
a scanning stopping module, configured to stop scanning when the second determination module determines that the bluetooth device information matches the identifier of the target bluetooth device;
the communication module is further configured to establish connection and communication with a target bluetooth device according to the bluetooth device information matched with the identifier of the target bluetooth device when the second determination module determines that the bluetooth device information is matched with the identifier of the target bluetooth device, and then the connection and communication is completed;
the device further comprises: a deletion module;
the deletion module specifically includes: a deleting unit, a scanning unit and a judging unit;
the deleting unit is used for deleting the Bluetooth device information matched with the identifier of the target Bluetooth device from an operating system when the first judging module judges that the paired Bluetooth device information contains the Bluetooth device information matched with the identifier of the target Bluetooth device; triggering a scanning unit;
the scanning unit is used for scanning surrounding Bluetooth equipment;
the judging unit is used for acquiring the Bluetooth device information of the scanned Bluetooth device when the scanning unit scans the Bluetooth device, and judging whether the acquired Bluetooth device information is matched with the identifier of the target Bluetooth device acquired by the first acquiring module;
the communication module is used for establishing connection and communication with a target Bluetooth device according to the Bluetooth device information matched with the target Bluetooth device when the judgment unit judges that the acquired Bluetooth device information is matched with the identifier of the target Bluetooth device, and ending; and the second judging module is further configured to establish connection and communication with the target bluetooth device according to the bluetooth device information matched with the identifier of the target bluetooth device when judging that the bluetooth device information is matched with the identifier of the target bluetooth device, and then the operation is finished.
10. The apparatus of claim 9, further comprising: detecting a module and starting a Bluetooth module;
the detection module is used for checking whether the Bluetooth is started or not;
the starting Bluetooth module is used for starting Bluetooth when the detection module does not start Bluetooth;
the first acquisition module is used for acquiring the identifier of the target Bluetooth device when the detection module detects that Bluetooth is started; and the Bluetooth module is also used for acquiring the identifier of the target Bluetooth equipment after the Bluetooth module is started to start Bluetooth.
11. The apparatus of claim 9, wherein the first obtaining module is specifically configured to obtain a pre-stored or user-entered identifier of the target bluetooth device.
12. The apparatus of claim 9, wherein the first obtaining module is specifically configured to obtain, from the server, the identifier of the target bluetooth device matching the login information according to the login information input by the user.
13. The apparatus of claim 9, further comprising: a setting module and a third judging module;
the setting module is used for setting an initial value of scanning time;
the third judging module is configured to judge whether the scanning time exceeds a preset time when the second judging module judges that the bluetooth device information does not match the identifier of the target bluetooth device;
the ending module is further used for ending when the third judging module judges that the scanning time exceeds the preset time;
the scanning module is further configured to scan the peripheral bluetooth devices when the third determining module determines that the scanning time does not exceed the preset time.
14. The apparatus according to claim 9, wherein the communication module is specifically configured to, when the first determining module determines that there is bluetooth device information that matches the identifier of the target bluetooth device in the paired bluetooth device information, obtain a MAC address from the bluetooth device information that matches the identifier of the target bluetooth device, send a connection request to the target bluetooth device according to the MAC address, and when the connection is successful, perform communication, and then end; and the second judging module is further configured to, when judging that the bluetooth device information matches the identifier of the target bluetooth device, acquire an MAC address from the bluetooth device information matching the identifier of the target bluetooth device, send a connection request to the target bluetooth device according to the MAC address, and when the connection is successful, perform communication, and then end.
15. The apparatus of claim 9, further comprising: the storage module and the fourth judgment module;
the storage module is configured to store the acquired bluetooth device information after the second determination module determines that the acquired bluetooth device information matches with the identifier of the target bluetooth device;
the fourth judging module is configured to acquire the stored bluetooth device information from the storage module, and judge whether there is bluetooth device information in the acquired bluetooth device information that matches the identifier of the target bluetooth device acquired by the first acquiring module;
the second obtaining module is specifically configured to obtain paired bluetooth device information from an operating system when the fourth determining module determines that there is no bluetooth device information that matches the identifier of the target bluetooth device in the obtained bluetooth device information;
the communication module is further configured to, when the fourth determination module determines that the acquired bluetooth device information includes bluetooth device information that matches the identifier of the target bluetooth device, establish connection and communication with the target bluetooth device according to the bluetooth device information that matches the identifier of the target bluetooth device, and then end the process.
CN201711157271.8A 2017-11-20 2017-11-20 Method and device for establishing Bluetooth connection Active CN107770762B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201711157271.8A CN107770762B (en) 2017-11-20 2017-11-20 Method and device for establishing Bluetooth connection

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201711157271.8A CN107770762B (en) 2017-11-20 2017-11-20 Method and device for establishing Bluetooth connection

Publications (2)

Publication Number Publication Date
CN107770762A CN107770762A (en) 2018-03-06
CN107770762B true CN107770762B (en) 2020-05-19

Family

ID=61278264

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201711157271.8A Active CN107770762B (en) 2017-11-20 2017-11-20 Method and device for establishing Bluetooth connection

Country Status (1)

Country Link
CN (1) CN107770762B (en)

Families Citing this family (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111194097A (en) * 2018-11-14 2020-05-22 奇酷互联网络科技(深圳)有限公司 Mobile terminal, Bluetooth connection method and storage device
CN109413629A (en) * 2018-11-20 2019-03-01 智车优行科技(北京)有限公司 Bluetooth reconnection method
CN113132962B (en) * 2019-04-16 2022-12-06 华为技术有限公司 Bluetooth scanning method and electronic equipment
CN113727291A (en) * 2020-05-26 2021-11-30 菜鸟智能物流控股有限公司 Equipment interaction method, device, server and data processing method
CN111542040B (en) * 2020-07-07 2020-10-13 飞天诚信科技股份有限公司 Method and device for enhancing Bluetooth connection stability
CN111935694B (en) * 2020-10-15 2021-03-16 飞天诚信科技股份有限公司 Bluetooth device connection method and device, electronic device and readable storage medium
CN113490194A (en) * 2021-08-02 2021-10-08 Oppo广东移动通信有限公司 Bluetooth-based equipment connection method and device, electronic equipment and storage medium
CN113473434A (en) * 2021-08-17 2021-10-01 杭州涂鸦信息技术有限公司 Bluetooth connection method, device, computer equipment and computer readable storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102999251A (en) * 2012-10-31 2013-03-27 东莞宇龙通信科技有限公司 Terminal and equipment connection management method
CN104967971A (en) * 2015-06-26 2015-10-07 飞天诚信科技股份有限公司 Method achieving bluetooth automatic return connection in Android system
EP2953387A1 (en) * 2014-06-06 2015-12-09 EM Microelectronic-Marin SA Method and system for bidirectional communications via a bluetooth low energy advertise link
CN105516897A (en) * 2015-12-07 2016-04-20 哈尔滨工业大学深圳研究生院 Method and device for one-key establishment of communication connection between Bluetooth devices

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102999251A (en) * 2012-10-31 2013-03-27 东莞宇龙通信科技有限公司 Terminal and equipment connection management method
EP2953387A1 (en) * 2014-06-06 2015-12-09 EM Microelectronic-Marin SA Method and system for bidirectional communications via a bluetooth low energy advertise link
CN104967971A (en) * 2015-06-26 2015-10-07 飞天诚信科技股份有限公司 Method achieving bluetooth automatic return connection in Android system
CN105516897A (en) * 2015-12-07 2016-04-20 哈尔滨工业大学深圳研究生院 Method and device for one-key establishment of communication connection between Bluetooth devices

Also Published As

Publication number Publication date
CN107770762A (en) 2018-03-06

Similar Documents

Publication Publication Date Title
CN107770762B (en) Method and device for establishing Bluetooth connection
CN106681774B (en) Software upgrading method of Bluetooth loudspeaker and intelligent terminal
CN111464994B (en) Method and system for realizing public search of Bluetooth equipment
CN106201574B (en) Application interface starting method and device
CN109005532B (en) Bluetooth connection method, Bluetooth master device and Bluetooth slave device
CN108040329B (en) The load and its management method of eSIM module and its subscription data
US10492245B2 (en) Call termination method, application processor, and modem
EP2611226A1 (en) Processing method and system for over-the-air bootstrap
CN105025433A (en) Bluetooth pairing method and terminal
US20190166552A1 (en) Network search method and apparatus under double-card mode, and computer storage medium
CN106211355B (en) Equipment and system for controlling data interaction and working method thereof
CN112203179A (en) TWS earphone, automatic reconnection method and device thereof, and computer storage medium
EP2770766A1 (en) Displaying stored data while provisioning service functionalities of a mobile terminal
US20170318483A1 (en) Self-recovery method and device after disconnection of base station
CN112566104B (en) Roaming coordination method based on Mesh network, wireless access point and storage medium
CN111212155A (en) Log debugging method, television and storage medium
CN108541078B (en) Terminal binding method, system, terminal and server
CN115065691B (en) Communication implementation method and device based on android platform
KR20170084907A (en) Communication device and control method thereof
CN112543493A (en) Wifi connection method, terminal and computer storage medium
CN107994928B (en) Method and communication device for realizing synchronous receiving and transmitting of Bluetooth data
CN113543102A (en) Bluetooth connection method
CN110187905B (en) System updating method and mobile terminal
CN105007589B (en) Parameter configuration method, machine-card integrated terminal device and server
CN108834116B (en) Bluetooth pairing method, electronic device and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant