Bluethooth LE Library for Codename One apps. This library now uses a native Codename One bridge implementation adapted from the original Bluetooth LE plugin lineage.
This library can be added to a Codename One project in either of these ways.
Add the library dependency to your project pom.xml:
<dependency>
<groupId>com.codenameone</groupId>
<artifactId>cn1-bluetooth-lib</artifactId>
<version>1.0.0</version>
<type>pom</type>
</dependency>This is the same dependency form used by the sample app in BTDemo/pom.xml.
- Build or download the
.cn1libartifact for this library. - Add the
.cn1libfile into your project'slib/directory. - In the Codename One project, run
Refresh Libs. - Clean and rebuild the project.
The library requires Java 8, as declared in common/codenameone_library_required.properties.
- See docs/API.md for call-by-call API documentation and behavior notes.
final Bluetooth bt = new Bluetooth();
Form main = new Form("Bluetooth Demo");
main.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
main.add(new Button(new Command("enable bluetooth") {
@Override
public void actionPerformed(ActionEvent evt) {
try {
if (!bt.isEnabled()) {
bt.enable();
}
if (!bt.hasPermission()) {
bt.requestPermission();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
}));
main.add(new Button(new Command("initialize") {
@Override
public void actionPerformed(ActionEvent evt) {
try {
bt.initialize(true, false, "bluetoothleplugin");
} catch (IOException ex) {
ex.printStackTrace();
}
}
}));- Steve Hannah - for the https://github.com/shannah/CN1JSON
- Rand Dusing - for the original bluetoothle plugin lineage