{"id":13848060,"url":"https://github.com/palaima/AndroidSmoothBluetooth","last_synced_at":"2025-07-12T11:33:11.015Z","repository":{"id":26660823,"uuid":"30117183","full_name":"palaima/AndroidSmoothBluetooth","owner":"palaima","description":"Smooth communication via bluetooth with other android devices or microcontrollers such as Arduino.","archived":false,"fork":false,"pushed_at":"2019-04-05T13:15:19.000Z","size":297,"stargazers_count":196,"open_issues_count":10,"forks_count":74,"subscribers_count":18,"default_branch":"master","last_synced_at":"2024-11-14T04:12:24.545Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/palaima.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-01-31T16:00:47.000Z","updated_at":"2024-10-07T13:59:11.000Z","dependencies_parsed_at":"2022-07-25T15:48:24.054Z","dependency_job_id":null,"html_url":"https://github.com/palaima/AndroidSmoothBluetooth","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palaima%2FAndroidSmoothBluetooth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palaima%2FAndroidSmoothBluetooth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palaima%2FAndroidSmoothBluetooth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palaima%2FAndroidSmoothBluetooth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/palaima","download_url":"https://codeload.github.com/palaima/AndroidSmoothBluetooth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225820303,"owners_count":17529138,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-04T19:00:40.027Z","updated_at":"2024-11-21T23:30:54.810Z","avatar_url":"https://github.com/palaima.png","language":"Java","funding_links":[],"categories":["Java","Libs","Bluetooth"],"sub_categories":["\u003cA NAME=\"Bluetooth\"\u003e\u003c/A\u003eBluetooth"],"readme":"# Android Smooth Bluetooth\n\n[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Android%20Smooth%20Bluetooth-brightgreen.svg?style=flat)](http://android-arsenal.com/details/1/1859)\n\nSmooth communication via bluetooth with other android devices or microcontrollers such as Arduino.\n\n## Getting Started\n\nAdd Gradle dependency:\n\n```gradle\ndependencies {\n   compile 'io.palaima:smoothbluetooth:0.1.0'\n}\n```\n\n* Or\n[Download from Maven](https://oss.sonatype.org/content/repositories/releases/io/palaima/smoothbluetooth/0.1.0/smoothbluetooth-0.1.0.aar)\n\nYou can try the SNAPSHOT version:\n\n```gradle\ndependencies {\n   compile 'io.palaima:smoothbluetooth:0.2.0-SNAPSHOT'\n}\n```\nMake sure to add the snapshot repository:\n\n```gradle\nrepositories {\n    maven {\n        url \"https://oss.sonatype.org/content/repositories/snapshots\"\n    }\n}\n```\n\n## Usage\n\n### 1. Declare bluetooth permissions in AndroidManifest.xml\n```xml\n\u003cuses-permission android:name=\"android.permission.BLUETOOTH\" /\u003e\n\u003cuses-permission android:name=\"android.permission.BLUETOOTH_ADMIN\" /\u003e\n```\n### 2. Define SmoothBluetooth instance\n```java\nprivate SmoothBluetooth mSmoothBluetooth;\n\n@Override\nprotected void onCreate(Bundle savedInstanceState) {\n    super.onCreate(savedInstanceState);\n    mSmoothBluetooth = new SmoothBluetooth(Context context);\n}\n```\nthere are possible overrides:\n```java\nmSmoothBluetooth = new SmoothBluetooth(Context context, SmoothBluetooth.Listener listener);\n```\nor\n```java\nmSmoothBluetooth = new SmoothBluetooth(Context context, ConnectionTo connectionTo, Connection connection, SmoothBluetooth.Listener listener);\n```\n\n`ConnectionTo` defines to what type of device to connect with (by default it is `ConnectionTo.OTHER_DEVICE` which means microcontrollers like Arduino)\n\n```java\nConnectionTo.ANDROID_DEVICE\nConnectionTo.OTHER_DEVICE\n```\n\n`Connection` defines what type of connection will be (be default it is `Connection.SECURE`)\n\n```java\nConnection.SECURE\nConnection.INSECURE\n```\n### 3. Define SmoothBluetooth.Listener\nAfter 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)`\n\n```java\nprivate SmoothBluetooth.Listener mListener = new SmoothBluetooth.Listener() {\n    @Override\n    public void onBluetoothNotSupported() {\n        //device does not support bluetooth\n    }\n\n    @Override\n    public void onBluetoothNotEnabled() {\n        //bluetooth is disabled, probably call Intent request to enable bluetooth\n    }\n\n    @Override\n    public void onConnecting(Device device) {\n        //called when connecting to particular device\n    }\n\n    @Override\n    public void onConnected(Device device) {\n       //called when connected to particular device\n    }\n\n    @Override\n    public void onDisconnected() {\n        //called when disconnected from device\n    }\n\n    @Override\n    public void onConnectionFailed(Device device) {\n        //called when connection failed to particular device\n    }\n\n    @Override\n    public void onDiscoveryStarted() {\n        //called when discovery is started\n    }\n\n    @Override\n    public void onDiscoveryFinished() {\n        //called when discovery is finished\n    }\n\n    @Override\n    public void onNoDevicesFound() {\n        //called when no devices found\n    }\n\n    @Override\n    public void onDevicesFound(final List\u003cDevice\u003e deviceList,\n            final BluetoothHelper.ConnectionCallback connectionCallback) {\n        //receives discovered devices list and connection callback\n        //you can filter devices list and connect to specific one\n        //connectionCallback.connectTo(deviceList.get(position));\n    }\n\n    @Override\n    public void onDataReceived(int data) {\n        //receives all bytes\n    }\n};\n```\n\n### 4. Try to connect\nAfter everything is set up and all is left to do is try to connect\n\n```java\nmSmoothBluetooth.tryConnection();\n```\n`tryConnection()` is linked with `SmoothBluetooth.Listener` so all connection events will be passed to listener.\nBy default if everything is ok, immediately returns all paired devices to `SmoothBluetooth.Listener`'s `onDevicesFound`\n\n### 5. Discovering\n```java\nmSmoothBluetooth.doDiscovery();\n```\nCall `doDiscovery()` method which search for unpaired devices and returns them to `SmoothBluetooth.Listener`'s `onDevicesFound`\n\n### 6. Sending data\n```java\nmSmoothBluetooth.send(byte[] data, boolean CRLF);\n```\nor\n```java\nmSmoothBluetooth.send(String data, boolean CRLF);\n```\n`boolean CRLF` indicates if data is need to be send with ending by LF and CR or not.\nif you do not need CRLF at the end there are some overrides with `CRLF = false`\n```java\nmSmoothBluetooth.send(byte[] data);\nmSmoothBluetooth.send(String data);\n```\n\n### 6. Disconnect\n\n```java\nmSmoothBluetooth.disconnect();\n```\n\n### 7. Do not forget to stop\nFor instance in your activity where `SmoothBluetooth` is defined you must call `stop()`\n```java\n@Override\nprotected void onDestroy() {\n    super.onDestroy();\n    mSmoothBluetooth.stop();\n}\n```\n\n## Sample\n\nYou can clone the project and compile it yourself (it includes a sample).\n[MainActivity](https://github.com/palaima/AndroidSmoothBluetooth/blob/master/app/src/main/java/io/palaima/smoothbluetooth/app/MainActivity.java)\n\n## Contributing\nWant to contribute? You are welcome!\nNote that all pull request should go to `dev` branch.\n\nDeveloped By\n------------\n\n* Mantas Palaima - \u003cpalaima.mantas@gmail.com\u003e\n\nCredits\n------------\n\nCredit to Aidan Follestad's [Material Dialogs](https://github.com/afollestad/material-dialogs) library.\n\nLicense\n--------\n\n    Copyright 2015 Mantas Palaima.\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpalaima%2FAndroidSmoothBluetooth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpalaima%2FAndroidSmoothBluetooth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpalaima%2FAndroidSmoothBluetooth/lists"}