CN107770762A - A kind of method and device for establishing bluetooth connection - Google Patents

A kind of method and device for establishing bluetooth connection Download PDF

Info

Publication number
CN107770762A
CN107770762A CN201711157271.8A CN201711157271A CN107770762A CN 107770762 A CN107770762 A CN 107770762A CN 201711157271 A CN201711157271 A CN 201711157271A CN 107770762 A CN107770762 A CN 107770762A
Authority
CN
China
Prior art keywords
bluetooth
bluetooth equipment
identifier
target
equipment information
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.)
Granted
Application number
CN201711157271.8A
Other languages
Chinese (zh)
Other versions
CN107770762B (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

Landscapes

  • Mobile Radio Communication Systems (AREA)

Abstract

The present invention relates to the communications field, more particularly to a kind of method and device for establishing bluetooth connection, this method includes:Application program obtains the identifier of target Bluetooth devices;The bluetooth equipment information matched is obtained from operating system, when there is the bluetooth equipment information that the identifier with the target Bluetooth devices matches in the bluetooth equipment information matched, is established with target Bluetooth devices and connects and communicate;When the bluetooth equipment information not matched in the bluetooth equipment information matched with the identifier of the target Bluetooth devices, scan surrounding bluetooth equipment, when the bluetooth equipment information of scanning to bluetooth equipment matches with the identifier of the target Bluetooth devices, established with target Bluetooth devices and connect and communicate;Not carried out bluetooth connection by operating system in advance by user the invention enables the operation carried out in application program is influenceed.

Description

A kind of method and device for establishing bluetooth connection
Technical field
The present invention relates to the communications field, more particularly to a kind of method and device for establishing bluetooth connection.
Background technology
Bluetooth is a kind of radiotechnics of short haul connection between holding equipment, because Bluetooth technology transmission range is big, anti- Interference waits by force many advantages so that Bluetooth function has become the standard configuration function of mobile terminal such as smart mobile phone.
In the prior art, there is the scanning linkage function for bluetooth equipment in the application program of mobile device;So And user is when using application program, custom first passes through scanning connection bluetooth equipment in the operating system of mobile device, returns again to The operation related to bluetooth equipment is carried out in application program;Because bluetooth equipment may be completed to match with terminal device, therefore should The problem of scanning less than bluetooth equipment or not connecting bluetooth equipment occurs with program.
The content of the invention
To solve technological deficiency of the prior art, the present invention proposes a kind of method and device for establishing bluetooth connection.
A kind of method for establishing bluetooth connection provided by the invention, including:
Step S1, application program obtains the identifier of target Bluetooth devices;
Step S2, application program obtains the bluetooth equipment information matched from operating system, and judges the indigo plant matched The bluetooth equipment information for whether having the identifier with target Bluetooth devices to match in tooth facility information, it is then to perform step S4, Otherwise surrounding bluetooth equipment is scanned, when bluetooth equipment is arrived in scanning, performs step S3;
Step S3, application program obtains the bluetooth equipment information of the bluetooth equipment scanned, and judges the bluetooth got Whether facility information matches with the identifier of target Bluetooth devices, is then to stop scanning, performs step S4, otherwise report an error end;
Step S4, application program is blue with target according to the bluetooth equipment information that the identifier with target Bluetooth devices matches Tooth equipment, which is established, to be connected and communicates, and is terminated.
A kind of device for establishing bluetooth connection provided by the invention, including:
First acquisition module, for obtaining the identifier of target Bluetooth devices;
Second acquisition module, for obtaining the bluetooth equipment information matched from operating system;
First judge module, whether have in the bluetooth equipment information matched got for judging the second acquisition module The bluetooth equipment information that the identifier of the target Bluetooth devices got with the first acquisition module matches;
Communication module, for judging to have in the bluetooth equipment information matched and target Bluetooth devices when the first judge module Identifier match bluetooth equipment information when, the bluetooth equipment information that is matched according to the identifier with target Bluetooth devices Established with target Bluetooth devices and connect and communicate, terminated;
Scan module, for judging not set with target Bluetooth in the bluetooth equipment information matched when the first judge module During the bluetooth equipment information that standby identifier matches, surrounding bluetooth equipment is scanned;
3rd acquisition module, for when bluetooth equipment is arrived in scan module scanning, obtaining the indigo plant of the bluetooth equipment scanned Tooth facility information;
Second judge module, the bluetooth equipment information of the bluetooth equipment got for judging the 3rd acquisition module whether with The identifier matching for the target Bluetooth devices that first acquisition module is got;
Terminate module, for not judging the identifiers of bluetooth equipment information and target Bluetooth devices not when the second judge module Timing, report an error end;
Stop scan module, for judging bluetooth equipment information and the identifier of target Bluetooth devices when the second judge module During matching, stop scanning;
Communication module, it is additionally operable to when the second judge module judges bluetooth equipment information and the identifier of target Bluetooth devices Timing, the bluetooth equipment information to be matched according to the identifier with target Bluetooth devices are established with target Bluetooth devices and connect and lead to Letter, terminate.
Had the beneficial effect that using what above-mentioned technical proposal reached:Terminal device adds pair before bluetooth equipment is connected Detection and judgement of unpaired message in operating system etc. are operated so that the operation carried out in application program is not led in advance by user Cross the influence that operating system carries out bluetooth connection.
Brief description of the drawings
Fig. 1 is a kind of flow chart for method for establishing bluetooth connection that the embodiment of the present invention 1 provides;
Fig. 2 is a kind of flow chart for method for establishing bluetooth connection that the embodiment of the present invention 2 provides;
Fig. 3 is a kind of block diagram for device for establishing bluetooth connection that the embodiment of the present invention 3 provides.
Embodiment
To make the object, technical solutions and advantages of the present invention clearer, below in conjunction with accompanying drawing to embodiment party of the present invention Formula, which is done, to be further described in detail.
Embodiment 1
A kind of method for establishing bluetooth connection is present embodiments provided, this method is applied to the shifting of Android operation system In dynamic terminal, referring to Fig. 1, including:
Step 101, application program detect whether to have been switched on bluetooth, are then to perform step 103, otherwise perform step 102;
Specifically, application call system interface function BluetoothAdapter.getDefaultAdapter () .isEnabled (), judge to call the return value of the function no as true, be that application program judges to have turned on bluetooth, performs Step 103, otherwise application program judges not open bluetooth, performs step 102.
Step 102, application program open bluetooth;
Specifically, application program creates the startup event that bluetooth is opened in a request first, and by calling a readjustment Function judges to open whether bluetooth module succeeds, step 103 is continued executing with if opening successfully, otherwise opens failure, report an error knot Beam;
The request to create opens being implemented as the startup event of bluetooth:Intent intent=new Intent (BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(intent,CODE_TURN_ON_BT);
Intent therein is that an event of android system starts object, startActivityForResult letters Number be to android system passback request an interface function, CODE_TURN_ON_BT be one be used for represent to The request flag of android system request;
It is described by call a call back function judge unlatching bluetooth module whether be specially successfully:Under heavily loaded Activity OnActivityResult (int requestCode, int resultCode, Intent data) function, judge heavy duty should The return value resultCode that function obtains, if resultCode==Activity.RESULT_OK, start bluetooth into Work(, illustrate that user eliminates opening android system if resultCode==Activity.RESULT_CANCELED The operation of bluetooth, start bluetooth failure.
Step 103, application program obtain the identifier of target Bluetooth devices;
The identifier of target Bluetooth devices can be:The sequence number of target Bluetooth devices or the title of target Bluetooth devices Or other can identify the data of bluetooth equipment;
Specifically, application program obtains the identifier of the target Bluetooth devices to prestore;
In more detail, application program obtains the sequence number of the target Bluetooth devices to prestore, and according to target Bluetooth devices Sequence number be converted to the title of target Bluetooth devices, it is necessary to which explanation, the title of bluetooth equipment is according to preset rules The identifier of target Bluetooth devices;
For example, in the present embodiment, the Serial No. for the target Bluetooth devices that application program is got: 650230000000173, application program deletes the front three of the sequence number, and is spliced to obtain with preset characters string FT_ The title FT_230000000173 of target Bluetooth devices;
Optionally, application program receives the identifier of the target Bluetooth devices of user's input;
In more detail, application program receives the sequence number of the target Bluetooth devices of user's input, and according to target Bluetooth The sequence number of equipment is converted to the title of target Bluetooth devices, it is necessary to explanation, the title of bluetooth equipment according to preset rules The as identifier of target Bluetooth devices;
Optionally, application program receives the log-on message of user's input, and obtains from server and stepped on what user inputted Record the identifier of the target Bluetooth devices of information match;
Step 104, application program judge the bluetooth equipment information matched whether can be got in an operating system, are Step 105 is then performed, otherwise performs step 107;
It should be noted that the identifier and bluetooth of bluetooth equipment are comprised at least in every bluetooth equipment information matched The MAC Address of equipment;
Specifically, application call system function BluetoothAdapter.getDefaultAdapter () .getBondedDevices();The data of call function return are received, then application program judges behaviour for space-time when returning not Make that the bluetooth equipment information matched can be got in system, do not have when being returned as space-time in application program decision system then There is the bluetooth equipment information for getting and having matched.
In the present embodiment, the data for the return that application program receives are specially [ABC_1000000028 (CE:EB:0C: 37:DF:5F),BK_FT1067(F3:24:E2:8A:2F:47),FT_230000000173(C4:5D:37:6B:F9:9F)];This It is specific as follows to get three bluetooth equipment information for application program in embodiment:
The identifier of bluetooth equipment The MAC Address of bluetooth equipment
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
Whether step 105, application program judge to have in the bluetooth equipment information of pairing in operating system and target Bluetooth The bluetooth equipment information that the identifier of equipment matches, it is then to perform step 106, otherwise performs step 107;
Specifically, application program searches bag according to the identifier of target Bluetooth devices in the bluetooth equipment information matched The bluetooth equipment information of identifier containing target Bluetooth devices, step 106 is performed if finding, is performed if not finding Step 107;
For example, set in the present embodiment according to the identifier FT_230000000173 of the target Bluetooth devices bluetooths found Standby information is the Article 3 in above-mentioned list.
In step 106, application program deletion action system matched in bluetooth equipment information with target Bluetooth devices The bluetooth equipment information that identifier matches;
Application program passes through getClass () .getMethod (" removeBond ", (Class according to the mode of reflection []) null) method gets removeBond () method, and performing removeBond () method can be in deletion action system The bluetooth equipment information to match in the bluetooth equipment information matched with the identifier of target Bluetooth devices, if the function returns It is true that it is no, which to return value, is then to delete successfully, deletes and fail if being flase if the return value of the function.
Step 107, application scan surrounding devices;When bluetooth equipment is arrived in scanning, step 108 is performed;
Specifically, application call current context context getSystemService (Context.BLUETOOTH_SERVICE) .getAdapter () .startLenScan (mBleScanCall) method is opened The operation of scanning device, adjusted back by mBleScanCall and return to scanning result;Scanning result is BluetoothDevice types Object, scanning result is the bluetooth equipment information of bluetooth equipment scanned;
Step 108, application program obtain scanning to the bluetooth equipment information of bluetooth equipment, and the bluetooth for judging to scan is set Whether standby information matches with the identifier of target Bluetooth devices, is then to perform step 109, otherwise return to step 107;
Specifically, bluetooth equipment information comprises at least the identifier of bluetooth equipment and the MAC Address of bluetooth equipment, this implementation In example, the bluetooth equipment information that application program is got is specially the title of bluetooth equipment and the MAC Address of bluetooth equipment.
For example, when scanning result is [FT_230000000173 (C4:5D:37:6B:F9:The indigo plant scanned is judged when 9F)] Tooth facility information matches with the identifier of target Bluetooth devices, otherwise judges the bluetooth equipment information and target indigo plant scanned The identifier of tooth equipment mismatches;
Preferably, also include before step 107:Application program sets the initial value of sweep time;
Accordingly, in step 108 application program judge the bluetooth equipment information of bluetooth equipment that scans whether with target The identifier of bluetooth equipment also includes when mismatching:Application program judges whether sweep time exceedes preset time, is to stop Scanning, terminate, otherwise return to step 107;
Step 109, application program stop scanning, and target Bluetooth devices are obtained from the bluetooth equipment information scanned MAC Address, and connection request is sent to target Bluetooth devices according to the MAC Address of target Bluetooth devices;
Specifically, application call current context context getSystemService (Context.BLUETOOTH_SERVICE) .getAdapter () .stopLenScan (mBleScanCall) method stops sweeping Retouch the operation of equipment.
Step 110, application program judge whether connection succeeds;It is then to perform step 111;Otherwise report an error end;
Specifically, application call connectGatt () method starts to connect, returned by mGattCallback readjustments Connection status is returned, when the status of return is that BluetoothGatt.GATT_SUCCESS is successful connection, otherwise connection is lost Lose.
Preferably, also include before step 110:Application program sets the initial value of the number of connection request;Step 110 it Also include afterwards:Application program update sends the number of connection request;
Accordingly, it is specially in step 110:Judge also to include during connection failure:Application program judges whether connect number It is then connection failure more than preset value, terminates, otherwise return to step 110;
Step 111, application program are communicated with target Bluetooth devices.
Preferably, also include in step 109:Application program preserves the bluetooth equipment information scanned;
Accordingly, also include between step 103 and step 104:Application program judges the bluetooth equipment information that itself is preserved In whether have the bluetooth equipment information that the identifier with target Bluetooth devices matches, be that application program is set from target Bluetooth The MAC Address of target Bluetooth devices is obtained in the bluetooth equipment information of standby information match, and according to the MAC of target Bluetooth devices Address sends connection request to target Bluetooth devices, performs step 110;Otherwise step 104 is performed.
Embodiment 2
The present embodiment provides a kind of method for establishing bluetooth connection, referring to Fig. 2, including:
Whether step 201, Application inspection bluetooth open, and are then to perform step 203, otherwise perform step 202;
Specifically, application call system interface function BluetoothAdapter.getDefaultAdapter () .isEnabled (), judge to call the return value of the function no as true, be that application program judges to have turned on bluetooth module, Step 203 is performed, otherwise application program judges not open bluetooth module, performs step 202.
Step 202, application program open bluetooth;
Specifically, application program creates the startup event that bluetooth is opened in a request first, show and by calling one Call back function judges to open whether bluetooth module succeeds, step 203 is continued executing with if opening successfully, otherwise opens failure, report Mistake terminates;
The request to create opens being implemented as the startup event of bluetooth:Intent intent=newIntent (BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(intent,CODE_TURN_ON_BT);
Intent therein is that an event of android system starts object, startActivityForResult letters Number be to android system passback request an interface function, CODE_TURN_ON_BT be one be used for represent to The request flag of android system request;
It is described by call a call back function judge unlatching bluetooth module whether be specially successfully:Under heavily loaded Activity OnActivityResult (int requestCode, int resultCode, Intentdata) function, judge heavy duty should The return value resultCode that function obtains, if resultCode==Activity.RESULT_OK, start bluetooth into Work(, illustrate that user eliminates opening android system if resultCode==Activity.RESULT_CANCELED The operation of bluetooth, start bluetooth failure.
Step 203, application program obtain the identifier of target Bluetooth devices;
The identifier of target Bluetooth devices can be:The sequence number of target Bluetooth devices or the title of target Bluetooth devices Or other can identify the data of bluetooth equipment;
Specifically, application program obtains the identifier of the target Bluetooth devices to prestore;
In more detail, application program obtains the sequence number of the target Bluetooth devices to prestore, and according to target Bluetooth devices Sequence number be converted to the title of target Bluetooth devices, it is necessary to which explanation, the title of bluetooth equipment is according to preset rules The identifier of target Bluetooth devices;
For example, in the present embodiment, the Serial No. for the target Bluetooth devices that application program is got: 650230000000173, application program deletes the front three of the sequence number, and is spliced to obtain with preset characters string FT_ The title FT_230000000173 of target Bluetooth devices;
Optionally, application program receives the identifier of the target Bluetooth devices of user's input;
In more detail, application program receives the sequence number of the target Bluetooth devices of user's input, and according to target Bluetooth The sequence number of equipment is converted to the title of target Bluetooth devices, it is necessary to explanation, the title of bluetooth equipment according to preset rules The as identifier of target Bluetooth devices;
Optionally, application program receives the log-on message of user's input, and obtains from server and stepped on what user inputted Record the identifier of the target Bluetooth devices of information match;
Step 204, application program judge the bluetooth equipment information matched whether can be got in an operating system, are Step 205 is then performed, otherwise performs step 207;
Specifically, application call system function BluetoothAdapter.getDefaultAdapter () .getBondedDevices();The data of call function return are received, then application program judges behaviour for space-time when returning not Make that the bluetooth equipment information matched can be got in system, do not have when being returned as space-time in application program decision system then There is the bluetooth equipment information for getting and having matched.
It should be noted that bluetooth equipment mark and bluetooth equipment are comprised at least in every bluetooth equipment information matched MAC Address;
In the present embodiment, the data for the return that application program receives are specially [ABC_1000000028 (CE:EB:0C: 37:DF:5F),BK_FT1067(F3:24:E2:8A:2F:47),FT_230000000173(C4:5D:37:6B:F9:9F)];This It is specific as follows to get three bluetooth equipment information for application program in embodiment:
For example, the bluetooth equipment information matched that application program is got is specially:
The title of bluetooth equipment The MAC Address of bluetooth equipment
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
Whether identification with target Bluetooth devices is had in the bluetooth equipment information that step 205, application program judge to have matched The bluetooth equipment information to match is accorded with, is then to perform step 206, otherwise performs step 207;
Mesh is obtained in the bluetooth equipment information that step 206, application program match from the identifier with target Bluetooth devices Mark the MAC Address of bluetooth equipment;Perform step 210;
Bluetooth equipment around step 207, application scan;After scanning is to bluetooth equipment, step 208 is performed;
Specifically, application call current context context getSystemService (Context.BLUETOOTH_SERVICE) .getAdapter () .startLenScan (mBleScanCall) method is opened The operation of scanning device, adjusted back by mBleScanCall and return to scanning result, represent successfully to be scanned behaviour when returning to true Make, perform step 208;
Step 208, application program obtain the bluetooth equipment information scanned;And judge the bluetooth of bluetooth equipment scanned Whether facility information matches with the identifier of target Bluetooth devices, is then to perform step 209, otherwise return to step 207;
Preferably, also include before step 207:Application program sets the initial value of sweep time;
Accordingly, in step 208 application program judge the bluetooth equipment information of bluetooth equipment that scans whether with target The identifier of bluetooth equipment also includes when mismatching:Application program judges whether sweep time exceedes preset time, is to stop Scanning, terminate, otherwise return to step 207;
Step 209, application program stop scanning;And the bluetooth equipment information to match from the identifier of target Bluetooth devices The middle MAC Address for obtaining target Bluetooth devices;
Specifically, application call current context context getSystemService (Context.BLUETOOTH_SERVICE) .getAdapter () .stopLenScan (mBleScanCall) method stops sweeping Retouch the operation of equipment.
Step 210, application program initiate connection request according to the MAC Address of target Bluetooth devices to target Bluetooth devices;
Step 211, application program judge whether connection succeeds, and are then to perform step 212, otherwise report an error end;
Specifically, application call connectGatt () method starts to connect, returned by mGattCallback readjustments Connection status is returned, when the status of return is that BluetoothGatt.GATT_SUCCESS is successful connection, otherwise connection is lost Lose.
Preferably, also include before step 211:Application program sets the initial value of the number of connection request;Step 211 it Also include afterwards:Application program update sends the number of connection request;
Accordingly, it is specially in step 211:Judge also to include during connection failure:Application program judges whether connect number It is then connection failure more than preset value, terminates, otherwise return to step 211;
Step 212, application program are communicated with target Bluetooth devices.
Preferably, step 209 also includes:Application program preserves the bluetooth equipment information scanned;
Accordingly, also include between step 203 and step 204:Application program judges the bluetooth equipment information that itself is preserved In whether have the bluetooth equipment information that the identifier with target Bluetooth devices matches, be that application program is set from target Bluetooth The MAC Address of target Bluetooth devices is obtained in the bluetooth equipment information of standby information match, and according to the MAC of target Bluetooth devices Address sends connection request to target Bluetooth devices, performs step 211;Otherwise step 204 is performed.
Embodiment 3
The present embodiment provides a kind of device for establishing bluetooth connection, as shown in figure 3, including:
First acquisition module 11, for obtaining the identifier of target Bluetooth devices;
Optionally, the first acquisition module 11, the target Bluetooth devices inputted specifically for obtaining prestore or user Identifier.
Optionally, the first acquisition module 11, specifically for being obtained according to the log-on message that user inputs from server with stepping on Record the identifier of the target Bluetooth devices of information match.
Second acquisition module 12, for obtaining the bluetooth equipment information matched from operating system;
First judge module 13, it is in the bluetooth equipment information matched got for judging the second acquisition module 12 The bluetooth equipment information that the no identifier for having the target Bluetooth devices got with the first acquisition module 11 matches;
Communication module 14, for having in the bluetooth equipment information that judges to have matched when the first judge module 13 and target Bluetooth During the bluetooth equipment information that the identifier of equipment matches, the bluetooth equipment that is matched according to the identifier with target Bluetooth devices Information is established with target Bluetooth devices and connects and communicate, and terminates;
Specifically, communication module 14, in judging the bluetooth equipment information matched when the first judge module 13 When having the bluetooth equipment information that the identifier with target Bluetooth devices matches, match from the identifier with target Bluetooth devices Bluetooth equipment information in obtain MAC Address, according to MAC Address to target Bluetooth devices send connection request, work as successful connection After communicated, terminate;
Scan module 15, in judging the bluetooth equipment information matched when the first judge module 13 with target indigo plant During the bluetooth equipment information that the identifier of tooth equipment matches, surrounding bluetooth equipment is scanned;
3rd acquisition module 16, for when bluetooth equipment is arrived in the scanning of scan module 15, obtaining the bluetooth equipment scanned Bluetooth equipment information;
Second judge module 17, the bluetooth equipment information of the bluetooth equipment got for judging the 3rd acquisition module 16 are The identifier of the no target Bluetooth devices got with the first acquisition module 11 matches;
Terminate module 18, for judging bluetooth equipment information and the identifier of target Bluetooth devices when the second judge module 17 During mismatch, report an error end;
Stop scan module 19, for judging the knowledge of bluetooth equipment information and target Bluetooth devices when the second judge module 17 When Fu not match, stop scanning;
Communication module 14, it is additionally operable to when second judges 17 pieces of identifications for judging bluetooth equipment information and target Bluetooth devices of mould During symbol matching, established and connected with target Bluetooth devices according to the bluetooth equipment information that the identifier with target Bluetooth devices matches And communicate, terminate.
Specifically, communication module 14, specifically for judging that bluetooth equipment information is set with target Bluetooth when the second judge module When standby identifier matches, MAC Address, root are obtained in the bluetooth equipment information to match from the identifier with target Bluetooth devices Connection request is sent to target Bluetooth devices according to MAC Address, is communicated, terminated after successful connection.
Preferably, the device also includes:Removing module;
Removing module specifically includes:Delete unit, scanning element and judging unit;
Unit is deleted, has in the bluetooth equipment information for judging to have matched for working as the first judge module 13 and is set with target Bluetooth During the bluetooth equipment information that standby identifier matches, the identifier with target Bluetooth devices is matched from operating system Bluetooth equipment information deletion;Driver sweep unit;
Scanning element, for scanning surrounding bluetooth equipment;
Judging unit, for when bluetooth equipment is arrived in scanning element scanning, the bluetooth for obtaining the bluetooth equipment scanned to be set Standby information, and judge the bluetooth equipment information that gets whether the knowledge of the target Bluetooth devices got with the first acquisition module 11 It Fu not match;
Accordingly, communication module 14, the bluetooth equipment information for judging to get when judging unit are set with target Bluetooth When standby identifier matches, connection is established simultaneously according to the bluetooth equipment information matched with target Bluetooth devices and target Bluetooth devices Communication, terminate;It is additionally operable to when the second judge module 17 judges that bluetooth equipment information matches with the identifier of target Bluetooth devices, The bluetooth equipment information to be matched according to the identifier with target Bluetooth devices is established with target Bluetooth devices and connects and communicate, and ties Beam.
Preferably, the device also includes:Detection module and unlatching bluetooth module;
Detection module, bluetooth is had been switched on for checking whether;
Bluetooth module is opened, for when detection module does not open bluetooth, opening bluetooth;
Accordingly, the first acquisition module 11, for obtaining target Bluetooth when detection module detects and has been switched on bluetooth The identifier of equipment;It is additionally operable to after bluetooth module unlatching bluetooth is opened, obtain the identifier of target Bluetooth devices.
Preferably, the device also includes:Setup module and the 3rd judge module;
Setup module, for setting the initial value of sweep time;
3rd judge module, for judging the identification of bluetooth equipment information and target Bluetooth devices when the second judge module 17 When symbol mismatches, judge whether sweep time exceedes preset time;
Accordingly, terminate module 18, it is additionally operable to when the 3rd judge module judges that sweep time exceedes preset time, knot Beam;
Scan module 15, it is additionally operable to when the 3rd judge module judges that sweep time is not above preset time around scanning Bluetooth equipment.
Preferably, the device also includes:Memory module and the 4th judge module;
Memory module, for judging the bluetooth equipment information that gets and target Bluetooth devices when the second judge module 17 Preserved after identifier matching and get bluetooth equipment information;
4th judge module, for obtaining the bluetooth equipment information of preservation from memory module, and judge the indigo plant got The bluetooth for whether having the identifier of the target Bluetooth devices got with the first acquisition module 11 to match in tooth facility information is set Standby information;
Accordingly, the second acquisition module 12, specifically for the bluetooth equipment information got when the judgement of the 4th judge module In do not match with the identifier of target Bluetooth devices bluetooth equipment information when, the indigo plant matched is obtained from operating system Tooth facility information;
Communication module 14, it is additionally operable to when the 4th judge module judges to have in the bluetooth equipment information that gets and target Bluetooth During the bluetooth equipment information that the identifier of equipment matches, the bluetooth equipment that is matched according to the identifier with target Bluetooth devices Information is established with target Bluetooth devices and connects and communicate, and terminates.
It should be noted that bluetooth equipment information specifically includes:The identifier of bluetooth equipment and the MAC of bluetooth equipment Location;The bluetooth equipment information to match with the identifier of target Bluetooth devices specifically includes:The identifier of target Bluetooth devices and The MAC Address of target Bluetooth devices;The identifier of target Bluetooth devices is specially the title or target indigo plant of target Bluetooth devices The sequence number of tooth equipment.
The foregoing is only a preferred embodiment of the present invention, but protection scope of the present invention be not limited thereto, Any one skilled in the art is in technical scope disclosed by the invention, the change or replacement that can readily occur in, It should all be included within the scope of the present invention.Therefore, protection scope of the present invention should be with scope of the claims It is defined.

Claims (17)

  1. A kind of 1. method for establishing bluetooth connection, it is characterised in that including:
    Step S1, application program obtains the identifier of target Bluetooth devices;
    Step S2, described application program obtains the bluetooth equipment information matched from operating system, and has been matched described in judgement Bluetooth equipment information in whether have the bluetooth equipment information that the identifier with the target Bluetooth devices matches, be to perform Step S4, surrounding bluetooth equipment is otherwise scanned, when bluetooth equipment is arrived in scanning, perform step S3;
    Step S3, described application program obtains the bluetooth equipment information of the bluetooth equipment scanned, and judges the bluetooth got Whether facility information matches with the identifier of the target Bluetooth devices, is then to stop scanning, performs step S4, otherwise report an error knot Beam;
    Step S4, the bluetooth equipment information and mesh that described application program matches according to the identifier with the target Bluetooth devices Mark bluetooth equipment, which is established, to be connected and communicates, and is terminated.
  2. 2. the method as described in claim 1, it is characterised in that in the step S2, when the application program judge described in After having the bluetooth equipment information that the identifier with the target Bluetooth devices matches in the bluetooth equipment information of pairing, perform Also include before step S4:
    The bluetooth that step 101, the application program match the identifier with the target Bluetooth devices from operating system Facility information is deleted, and scans surrounding bluetooth equipment, when bluetooth equipment is arrived in scanning, performs step 102;
    Step 102, the application program obtain the bluetooth equipment information of the bluetooth equipment scanned, and judge the bluetooth got Whether facility information matches with the identifier of the target Bluetooth devices, is then to stop scanning, continues executing with step S4, otherwise report Mistake terminates.
  3. 3. the method as described in claim 1, it is characterised in that also include before the step S1:Whether Application inspection Bluetooth is had been switched on, is then to perform step S1, otherwise opens bluetooth, perform step S1.
  4. 4. the method as described in claim 1, it is characterised in that the bluetooth equipment information specifically includes:The knowledge of bluetooth equipment Fu not be with the MAC Address of bluetooth equipment;The bluetooth equipment information to match with the identifier of the target Bluetooth devices is specifically wrapped Include:The identifier of target Bluetooth devices and the MAC Address of target Bluetooth devices;The identifier of the target Bluetooth devices is specially The title of target Bluetooth devices or the sequence number of target Bluetooth devices.
  5. 5. the method as described in claim 1, it is characterised in that the step S1 is specifically included:Application program obtains what is prestored Or the identifier of the target Bluetooth devices of user's input.
  6. 6. the method as described in claim 1, it is characterised in that the step S1 is specifically included:Application program is defeated according to user The log-on message entered obtains the identifier of the target Bluetooth devices to match with the log-on message from server.
  7. 7. the method as described in claim 1, it is characterised in that also include before bluetooth equipment around the scanning:Using journey Sequence sets the initial value of sweep time;
    Application program described in the step S3 judges the identification of the bluetooth equipment information and target Bluetooth devices got Symbol judges whether the sweep time exceedes preset time when mismatching, and is to terminate, otherwise continues executing with around the scanning Bluetooth equipment.
  8. 8. the method as described in claim 1, it is characterised in that the step S4 is specially:The application program from it is described MAC Address is obtained in the bluetooth equipment information that the identifier of target Bluetooth devices matches, is set according to MAC Address to target Bluetooth Preparation send connection request, is communicated after successful connection, terminates.
  9. 9. the method as described in claim 1, it is characterised in that in the step S3, when the application program judges to get Bluetooth equipment information matched with the identifier of the target Bluetooth devices after also include:The application program is preserved and got Bluetooth equipment information;
    After the step S1, also include before the step S2:The application program judges the bluetooth equipment letter itself preserved The bluetooth equipment information for whether having the identifier with the target Bluetooth devices to match in breath, it is then to perform step S4, otherwise Perform step S2.
  10. A kind of 10. device for establishing bluetooth connection, it is characterised in that including:
    First acquisition module, for obtaining the identifier of target Bluetooth devices;
    Second acquisition module, for obtaining the bluetooth equipment information matched from operating system;
    First judge module, for judging that second acquisition module is in the bluetooth equipment information matched described in getting The bluetooth equipment information that the no identifier for having the target Bluetooth devices got with first acquisition module matches;
    Communication module, for having and the target when in the bluetooth equipment information matched described in first judge module judgement During the bluetooth equipment information that the identifier of bluetooth equipment matches, according to the identifier phase with the target Bluetooth devices The bluetooth equipment information matched somebody with somebody is established with target Bluetooth devices and connects and communicate, and terminates;
    Scan module, in the bluetooth equipment information matched described in judging when first judge module not with the mesh During the bluetooth equipment information that the identifier of mark bluetooth equipment matches, surrounding bluetooth equipment is scanned;
    3rd acquisition module, for when bluetooth equipment is arrived in scan module scanning, obtaining the indigo plant of the bluetooth equipment scanned Tooth facility information;
    Second judge module, the bluetooth equipment information of the bluetooth equipment got for judging the 3rd acquisition module are The identifier of the no target Bluetooth devices got with first acquisition module matches;
    Terminate module, for judging the bluetooth equipment information and the knowledge of the target Bluetooth devices when second judge module When Fu not mismatch, report an error end;
    Stop scan module, for judging the bluetooth equipment information and the target Bluetooth devices when second judge module Identifier matching when, stop scanning;
    The communication module, it is additionally operable to when second judge module judges that the bluetooth equipment information is set with the target Bluetooth When standby identifier matches, the bluetooth equipment information and target Bluetooth that are matched according to the identifier with the target Bluetooth devices Equipment, which is established, to be connected and communicates, and is terminated.
  11. 11. device as claimed in claim 10, it is characterised in that also include:Removing module;
    The removing module specifically includes:Delete unit, scanning element and judging unit;
    The deletion unit, for have in the bluetooth equipment information matched described in judging when first judge module with it is described During the bluetooth equipment information that the identifier of target Bluetooth devices matches from operating system by with the target Bluetooth devices The bluetooth equipment information deletion that identifier matches;Driver sweep unit;
    The scanning element, for scanning surrounding bluetooth equipment;
    The judging unit, for when bluetooth equipment is arrived in scanning element scanning, obtaining the indigo plant of the bluetooth equipment scanned Tooth facility information, and judge the bluetooth equipment information that gets whether the mesh got with first acquisition module Mark the identifier matching of bluetooth equipment;
    The communication module, for when the bluetooth equipment information and the target Bluetooth that are got described in judging unit judgement During the identifier matching of equipment, established according to the bluetooth equipment information matched with the target Bluetooth devices and target Bluetooth devices Connect and communicate, terminate;It is additionally operable to when second judge module judges that the bluetooth equipment information is set with the target Bluetooth When standby identifier matches, the bluetooth equipment information and target Bluetooth that are matched according to the identifier with the target Bluetooth devices Equipment, which is established, to be connected and communicates, and is terminated.
  12. 12. device as claimed in claim 10, it is characterised in that also include:Detection module and unlatching bluetooth module;
    The detection module, bluetooth is had been switched on for checking whether;
    The unlatching bluetooth module, for when the detection module does not open bluetooth, opening bluetooth;
    First acquisition module, for obtaining target Bluetooth devices when the detection module detects and has been switched on bluetooth Identifier;It is additionally operable to after the unlatching bluetooth module opens bluetooth, obtain the identifier of target Bluetooth devices.
  13. 13. device as claimed in claim 10, it is characterised in that first acquisition module, specifically for obtaining what is prestored Or the identifier of the target Bluetooth devices of user's input.
  14. 14. device as claimed in claim 10, it is characterised in that first acquisition module, specifically for defeated according to user The log-on message entered obtains the identifier of the target Bluetooth devices to match with the log-on message from server.
  15. 15. device as claimed in claim 10, it is characterised in that also include:Setup module and the 3rd judge module;
    The setup module, for setting the initial value of sweep time;
    3rd judge module, for judging the bluetooth equipment information and the target Bluetooth when second judge module When the identifier of equipment mismatches, judge whether the sweep time exceedes preset time;
    The terminate module, it is additionally operable to, when the 3rd judge module judges that sweep time exceedes preset time, terminate;
    The scan module, it is additionally operable to the scanning week when the 3rd judge module judges that sweep time is not above preset time Enclose bluetooth equipment.
  16. 16. device as claimed in claim 10, it is characterised in that the communication module, specifically for when the described first judgement The bluetooth for having the identifier with the target Bluetooth devices to match in the bluetooth equipment information matched described in module judgement is set During standby information, MAC Address, root are obtained from the bluetooth equipment information to match with target Bluetooth devices identifiers Connection request is sent to the target Bluetooth devices according to the MAC Address, is communicated, terminated after successful connection;It is additionally operable to When second judge module judges that the bluetooth equipment information matches with the identifier of the target Bluetooth devices, from described Obtain MAC Address in the bluetooth equipment information to match with the identifier of the target Bluetooth devices, according to the MAC Address to Target Bluetooth devices send connection request, are communicated after successful connection, terminate.
  17. 17. device as claimed in claim 10, it is characterised in that also include:Memory module and the 4th judge module;
    The memory module, for the bluetooth equipment information got when second judge module judgement and the target Preserved after the identifier matching of bluetooth equipment and get bluetooth equipment information;
    4th judge module, for obtaining the bluetooth equipment information of preservation from the memory module, and judge to get Bluetooth equipment information in whether have what the identifiers of the target Bluetooth devices got with first acquisition module matched Bluetooth equipment information;
    Second acquisition module, specifically for when in the bluetooth equipment information got described in the 4th judge module judgement During the bluetooth equipment information not matched with the identifier of the target Bluetooth devices, obtain what is matched from operating system Bluetooth equipment information;
    The communication module, be additionally operable to judge when the 4th judge module described in have in the bluetooth equipment information that gets and institute When stating the bluetooth equipment information that the identifiers of target Bluetooth devices matches, according to described with target Bluetooth devices identifications Accord with the bluetooth equipment information to match to establish connection with target Bluetooth devices and communicate, terminate.
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 true CN107770762A (en) 2018-03-06
CN107770762B 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)

Cited By (8)

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

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

Cited By (12)

* 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
CN113132962A (en) * 2019-04-16 2021-07-16 华为技术有限公司 Bluetooth scanning method and electronic equipment
CN115580854A (en) * 2019-04-16 2023-01-06 华为技术有限公司 Bluetooth scanning method and electronic equipment
CN115580854B (en) * 2019-04-16 2023-08-04 华为技术有限公司 Bluetooth scanning method and electronic equipment
US11849376B2 (en) 2019-04-16 2023-12-19 Huawei Technologies Co., Ltd. Bluetooth scanning method and electronic device
CN113727291A (en) * 2020-05-26 2021-11-30 菜鸟智能物流控股有限公司 Equipment interaction method, device, server and data processing method
CN111542040A (en) * 2020-07-07 2020-08-14 飞天诚信科技股份有限公司 Method and device for enhancing Bluetooth connection stability
CN111935694A (en) * 2020-10-15 2020-11-13 飞天诚信科技股份有限公司 Bluetooth device connection method and device, electronic device and readable storage medium
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

Also Published As

Publication number Publication date
CN107770762B (en) 2020-05-19

Similar Documents

Publication Publication Date Title
CN107770762A (en) A kind of method and device for establishing bluetooth connection
CN101478458B (en) SIP protocol security test method
CN105307195B (en) A kind of method and device updating access point name parameter
CN101232509A (en) Equipment, system and method for supporting insulation mode network access control
US10701186B2 (en) Protocol format conversion method and apparatus, and interface platform
CN107071709A (en) A kind of matching method and device with bluetooth equipment
CN107360027A (en) The distribution method, apparatus and intelligent appliance of a kind of intelligent appliance
CN106487444A (en) A kind of method and system realizing mobile terminal and telecommunication apparatus data communication
CN104780204A (en) Method and system for rapidly sharing files between terminals
CN108040329A (en) The loading of eSIM modules and its subscription data and its management method
CN103546644A (en) Mobile terminal and communication method and device thereof
CN104363325B (en) Terminal paging method and system
CN107659999A (en) WIFI connection methods and equipment
CN106211355B (en) Equipment and system for controlling data interaction and working method thereof
CN101826967A (en) Data card and dial-up networking method
CN106028425A (en) Wireless communication connection control method and device
CN107659903A (en) The method and system opened automatically for realizing VoLTE business
CN104660728B (en) NAT penetrating methods based on intelligent home control system
CN106603374A (en) Automatic bridging method and system
CN106330513A (en) Processing method and apparatus for tr069 protocol information
CN107454659A (en) A kind of terminal identification method, system, terminal device and base station
CN105872996B (en) A kind of processing method and processing device of short message group chat
CN109068398B (en) Wireless connection method for mobile robot and manual operator and mobile robot system
CN106454439A (en) Advertisement resource transmission method and system
CN108541078B (en) Terminal binding method, system, terminal and server

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