百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
A

AndroidSmoothBluetooth

> 编程语言
开源

通过蓝牙与其他 Android 设备或微控制器(如 Arduino)进行流畅通信。

196 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

通过蓝牙与其他 Android 设备或微控制器(如 Arduino)进行流畅通信。

Android Smooth Bluetooth

Smooth communication via bluetooth with other android devices or microcontrollers such as Arduino.

Getting Started

Add Gradle dependency:

gradle
dependencies {
   compile 'io.palaima:smoothbluetooth:0.1.0'
}
  • Or Download from Maven

You can try the SNAPSHOT version:

gradle
dependencies {
   compile 'io.palaima:smoothbluetooth:0.2.0-SNAPSHOT'
}

Make sure to add the snapshot repository:

gradle
repositories {
    maven {
        url "https://oss.sonatype.org/content/repositories/snapshots"
    }
}

Usage

1. Declare bluetooth permissions in AndroidManifest.xml

xml

2. Define SmoothBluetooth instance

java
private SmoothBluetooth mSmoothBluetooth;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mSmoothBluetooth = new SmoothBluetooth(Context context);
}

there are possible overrides:

java
mSmoothBluetooth = new SmoothBluetooth(Context context, SmoothBluetooth.Listener listener);

or

java
mSmoothBluetooth = new SmoothBluetooth(Context context, ConnectionTo connectionTo, Connection connection, SmoothBluetooth.Listener listener);

ConnectionTo defines to what type of device to connect with (by default it is ConnectionTo.OTHER_DEVICE which means microcontrollers like Arduino)

java
ConnectionTo.ANDROID_DEVICE
ConnectionTo.OTHER_DEVICE

Connection defines what type of connection will be (be default it is Connection.SECURE)

java
Connection.SECURE
Connection.INSECURE

3. Define SmoothBluetooth.Listener

After that you must define SmoothBluetooth.Listener which catches all bluetooth related events and pass it to SmoothBluetooth constructor when defining its instance or if you already have SmoothBluetooth instance you can pass listener via setter setListener(SmoothBluetooth.Listener listener)

…

4. Try to connect

After everything is set up and all is left to do is try to connect

java
mSmoothBluetooth.tryConnection();

tryConnection() is linked with SmoothBluetooth.Listener so all connection events will be passed to listener. By default if everything is ok, immediately returns all paired devices to SmoothBluetooth.Listener's onDevicesFound

5. Discovering

java
mSmoothBluetooth.doDiscovery();

Call doDiscovery() method which search for unpaired devices and returns them to SmoothBluetooth.Listener's onDevicesFound

6. Sending data

java
mSmoothBluetooth.send(byte[] data, boolean CRLF);

or

java
mSmoothBluetooth.send(String data, boolean CRLF);

boolean CRLF indicates if data is need to be send with ending by LF and CR or not. if you do not need CRLF at the end there are some overrides with CRLF = false

java
mSmoothBluetooth.send(byte[] data);
mSmoothBluetooth.send(String data);

6. Disconnect

java
mSmoothBluetooth.disconnect();

7. Do not forget to stop

For instance in your activity where SmoothBluetooth is defined you must call stop()

java
@Override
protected void onDestroy() {
    super.onDestroy();
    mSmoothBluetooth.stop();
}

Sample

You can clone the project and compile it yourself (it includes a sample). MainActivity

Contributing

Want to contribute? You are welcome! Note that all pull request should go to dev branch.

Developed By

  • Mantas Palaima -

Credits

Credit to Aidan Follestad's Material Dialogs library.

License

Copyright 2015 Mantas Palaima.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Java

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言