1
1
# AndroidBluetoothLibrary
2
2
3
- A Library for easy implementation Bluetooth Classic and Low Energy on Android.
3
+ [ ![ Licence MIT] ( https://img.shields.io/badge/licence-MIT-blue.svg )] ( https://github.com/douglasjunior/AndroidBluetoothLibrary/blob/master/LICENSE )
4
+ [ ![ Release] ( https://jitpack.io/v/douglasjunior/AndroidBluetoothLibrary.svg )] ( https://jitpack.io/#douglasjunior/AndroidBluetoothLibrary )
5
+ [ ![ Downloads] ( https://jitpack.io/v/douglasjunior/AndroidBluetoothLibrary/month.svg )] ( #download )
6
+
7
+ A Library for easy implementation of Serial Bluetooth Classic and Low Energy on Android.
4
8
5
9
## Use
6
10
7
- ### Bluetooth Classic
11
+ ### Configuration
12
+
13
+ ``` java
14
+ BluetoothConfiguration config = new BluetoothConfiguration ();
15
+ config. context = getApplicationContext();
16
+ config. bluetoothServiceClass = BluetoothLeService . class; // BluetoothClassicService.class or BluetoothLeService.class
17
+ config. bufferSize = 1024 ;
18
+ config. characterDelimiter = ' \n ' ;
19
+ config. deviceName = " Your App Name" ;
20
+ config. callListenersInMainThread = true ;
21
+
22
+ // Bluetooth Classic
23
+ config. uuid = UUID . fromString(" 00001101-0000-1000-8000-00805f9b34fb" ); // Set null to find all devices on scan.
24
+
25
+ // Bluetooth LE
26
+ config. uuidService = UUID . fromString(" e7810a71-73ae-499d-8c15-faa9aef0c3f2" );
27
+ config. uuidCharacteristic = UUID . fromString(" bef8d6c9-9c21-4c9e-b632-bd58c1009f9f" );
28
+ config. transport = BluetoothDevice . TRANSPORT_LE ; // Only for dual-mode devices
29
+
30
+ BluetoothService . init(config);
31
+ ```
32
+
33
+ ### Getting BluetoothService
34
+
35
+ ``` java
36
+ BluetoothService service = BluetoothService . getDefaultInstance();
37
+ ```
38
+
39
+ ### Scanning
40
+
41
+ ``` java
42
+ service. setOnScanCallback(new BluetoothService .OnBluetoothScanCallback () {
43
+ @Override
44
+ public void onDeviceDiscovered (BluetoothDevice device , int rssi ) {
45
+ }
8
46
9
- Soon
47
+ @Override
48
+ public void onStartScan () {
49
+ }
10
50
11
- ### Bluetooth Low Energy
51
+ @Override
52
+ public void onStopScan () {
53
+ }
54
+ });
12
55
13
- Soon
56
+ service. startScan(); // See also service.stopScan();
57
+ ```
14
58
59
+ ### Connecting
60
+
61
+ ``` java
62
+ service. setOnEventCallback(new BluetoothService .OnBluetoothEventCallback () {
63
+ @Override
64
+ public void onDataRead (byte [] buffer , int length ) {
65
+ }
66
+
67
+ @Override
68
+ public void onStatusChange (BluetoothStatus status ) {
69
+ }
70
+
71
+ @Override
72
+ public void onDeviceName (String deviceName ) {
73
+ }
74
+
75
+ @Override
76
+ public void onToast (String message ) {
77
+ }
78
+
79
+ @Override
80
+ public void onDataWrite (byte [] buffer ) {
81
+ }
82
+ });
83
+
84
+ service. connect(device); // See also service.disconnect();
85
+ ```
86
+
87
+ ### Writing
88
+
89
+ ``` java
90
+ BluetoothWriter writer = new BluetoothWriter (service);
91
+
92
+ writer. writeln(" Your text here" );
93
+ ```
15
94
16
- ## Install
95
+ ## Download
17
96
18
97
1 . Add it in your root build.gradle at the end of repositories:
19
98
``` javascript
@@ -30,14 +109,14 @@ Soon
30
109
2.1. Bluetooth Classic
31
110
``` javascript
32
111
dependencies {
33
- compile ' com.github.douglasjunior.AndroidBluetoothLibrary:BluetoothClassicLibrary:0.3.1 '
112
+ compile ' com.github.douglasjunior.AndroidBluetoothLibrary:BluetoothClassicLibrary:0.3.2 '
34
113
}
35
114
```
36
115
37
116
2.2 . Bluetooth Low Energy
38
117
` ` ` javascript
39
118
dependencies {
40
- compile 'com.github.douglasjunior.AndroidBluetoothLibrary:BluetoothLowEnergyLibrary:0.3.1 '
119
+ compile 'com.github.douglasjunior.AndroidBluetoothLibrary:BluetoothLowEnergyLibrary:0.3.2 '
41
120
}
42
121
` ` `
43
122
59
138
60
139
## Contribute
61
140
62
- New features, bug fixes and improvements in the translation are welcome! For questions and suggestions use the [issues](https: // github.com/douglasjunior/AndroidBluetoothLibrary/issues).
141
+ New features, bug fixes and improvements are welcome! For questions and suggestions use the [issues](https: // github.com/douglasjunior/AndroidBluetoothLibrary/issues).
63
142
64
143
Before submit your PR , run the gradle check.
65
144
` ` ` bash
0 commit comments