{"id":24543832,"url":"https://github.com/douglasjunior/androidbluetoothlibrary","last_synced_at":"2025-04-06T07:15:57.945Z","repository":{"id":43531791,"uuid":"32959724","full_name":"douglasjunior/AndroidBluetoothLibrary","owner":"douglasjunior","description":"A Library for easy implementation of Serial Bluetooth Classic and Low Energy on Android. 💙","archived":false,"fork":false,"pushed_at":"2024-08-06T01:34:04.000Z","size":733,"stargazers_count":233,"open_issues_count":4,"forks_count":71,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-03-30T06:09:07.446Z","etag":null,"topics":["android","android-library","bluetooth","bluetooth-low-energy","hacktoberfest","java","jitpack","serial"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/douglasjunior.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"douglasjunior","patreon":"douglasjunior","custom":"paypal.me/douglasnassif"}},"created_at":"2015-03-27T00:40:12.000Z","updated_at":"2025-03-21T03:29:52.000Z","dependencies_parsed_at":"2025-01-24T09:45:29.475Z","dependency_job_id":null,"html_url":"https://github.com/douglasjunior/AndroidBluetoothLibrary","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/douglasjunior%2FAndroidBluetoothLibrary","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/douglasjunior%2FAndroidBluetoothLibrary/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/douglasjunior%2FAndroidBluetoothLibrary/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/douglasjunior%2FAndroidBluetoothLibrary/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/douglasjunior","download_url":"https://codeload.github.com/douglasjunior/AndroidBluetoothLibrary/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247445682,"owners_count":20939961,"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":["android","android-library","bluetooth","bluetooth-low-energy","hacktoberfest","java","jitpack","serial"],"created_at":"2025-01-22T20:15:16.059Z","updated_at":"2025-04-06T07:15:57.900Z","avatar_url":"https://github.com/douglasjunior.png","language":"Java","readme":"# AndroidBluetoothLibrary\n\n[![Licence MIT](https://img.shields.io/badge/licence-MIT-blue.svg)](https://github.com/douglasjunior/AndroidBluetoothLibrary/blob/master/LICENSE)\n[![Release](https://jitpack.io/v/douglasjunior/AndroidBluetoothLibrary.svg)](https://jitpack.io/#douglasjunior/AndroidBluetoothLibrary)\n[![Downloads](https://jitpack.io/v/douglasjunior/AndroidBluetoothLibrary/month.svg)](#download)\n[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Android%20Bluetooth%20Library-yellow.svg?style=flat)](http://android-arsenal.com/details/1/5821)\n\nA Library for easy implementation of Serial Bluetooth Classic and Low Energy on Android. 💙\n\n- Bluetooth Classic working from Android 2.1 (API 7)\n- Bluetooth Low Energy working from Android 4.3 (API 18)\n\n## Use\n\n### Configuration\n\n#### Bluetooth Classic\n```java\nBluetoothConfiguration config = new BluetoothConfiguration();\nconfig.context = getApplicationContext();\nconfig.bluetoothServiceClass = BluetoothClassicService.class;\nconfig.bufferSize = 1024;\nconfig.characterDelimiter = '\\n';\nconfig.deviceName = \"Your App Name\";\nconfig.callListenersInMainThread = true;\n\nconfig.uuid = UUID.fromString(\"00001101-0000-1000-8000-00805f9b34fb\"); // Required\n\nBluetoothService.init(config);\n```\n\n#### Bluetooth Low Energy\n```java\nBluetoothConfiguration config = new BluetoothConfiguration();\nconfig.context = getApplicationContext();\nconfig.bluetoothServiceClass = BluetoothLeService.class;\nconfig.bufferSize = 1024;\nconfig.characterDelimiter = '\\n';\nconfig.deviceName = \"Your App Name\";\nconfig.callListenersInMainThread = true;\n\nconfig.uuidService = UUID.fromString(\"e7810a71-73ae-499d-8c15-faa9aef0c3f2\"); // Required\nconfig.uuidCharacteristic = UUID.fromString(\"bef8d6c9-9c21-4c9e-b632-bd58c1009f9f\"); // Required\nconfig.transport = BluetoothDevice.TRANSPORT_LE; // Required for dual-mode devices\nconfig.uuid = UUID.fromString(\"00001101-0000-1000-8000-00805f9b34fb\"); // Used to filter found devices. Set null to find all devices.\n\nBluetoothService.init(config);\n```\n\n### Getting BluetoothService\n\n```java\nBluetoothService service = BluetoothService.getDefaultInstance();\n```\n\n### Scanning\n\n```java\nservice.setOnScanCallback(new BluetoothService.OnBluetoothScanCallback() {\n    @Override\n    public void onDeviceDiscovered(BluetoothDevice device, int rssi) {\n    }\n\n    @Override\n    public void onStartScan() {\n    }\n\n    @Override\n    public void onStopScan() {\n    }\n});\n\nservice.startScan(); // See also service.stopScan();\n```\n\n### Connecting\n\n```java\nservice.setOnEventCallback(new BluetoothService.OnBluetoothEventCallback() {\n    @Override\n    public void onDataRead(byte[] buffer, int length) {\n    }\n\n    @Override\n    public void onStatusChange(BluetoothStatus status) {\n    }\n\n    @Override\n    public void onDeviceName(String deviceName) {\n    }\n\n    @Override\n    public void onToast(String message) {\n    }\n\n    @Override\n    public void onDataWrite(byte[] buffer) {\n    }\n});\n\nservice.connect(device); // See also service.disconnect();\n```\n\n### Writing\n\n```java\nBluetoothWriter writer = new BluetoothWriter(service);\n\nwriter.writeln(\"Your text here\");\n```\n\n### Complete example\n\nSee the [sample project](https://github.com/douglasjunior/AndroidBluetoothLibrary/tree/master/Sample/src/main/java/com/github/douglasjunior/bluetoothsample).\n\n## Download \n\n1. Add it in your root build.gradle at the end of repositories:\n   ```javascript\n   allprojects {\n     repositories {\n       ...\n       maven { url \"https://jitpack.io\" }\n     }\n   }\n   ```\n\n2. Add the dependency\n\n   2.1. Bluetooth Classic\n     ```javascript\n     dependencies {\n       implementation 'com.github.douglasjunior.AndroidBluetoothLibrary:BluetoothClassicLibrary:0.3.5'\n     }\n     ```\n    \n   2.2. Bluetooth Low Energy\n     ```javascript\n     dependencies {\n       implementation 'com.github.douglasjunior.AndroidBluetoothLibrary:BluetoothLowEnergyLibrary:0.3.5'\n     }\n     ```\n \n3. Add permission in `AndroidManifest.xml` \n\n```xml\n\u003cmanifest ...\u003e\n  \u003cuses-permission android:name=\"android.permission.BLUETOOTH\" /\u003e\n  \u003cuses-permission android:name=\"android.permission.BLUETOOTH_ADMIN\" /\u003e\n  \u003cuses-permission android:name=\"android.permission.BLUETOOTH_PRIVILEGED\" /\u003e\n  \u003cuses-permission android:name=\"android.permission.ACCESS_COARSE_LOCATION\" /\u003e\n  ...\n\u003c/manifest\u003e\n```\n\n## Known Issues / Troubleshooting\n\n\u003cspan id=\"known-issues\" /\u003e\n\n- Scanning will not detect bluetooth devices if the user has denied Location Privacy Permission to your app. This library does not test for the permission and will not raise errors. (Android 6.0+) See: http://stackoverflow.com/a/33045489/2826279\n\n## Contribute\n\nNew features, bug fixes and improvements are welcome! For questions and suggestions use the [issues](https://github.com/douglasjunior/AndroidBluetoothLibrary/issues).\n\nBefore submit your PR, run the gradle check.\n```bash\n./gradlew build connectedCheck\n```\n\n\u003ca href=\"https://www.patreon.com/douglasjunior\"\u003e\u003cimg src=\"http://i.imgur.com/xEO164Z.png\" alt=\"Become a Patron!\" width=\"200\" /\u003e\u003c/a\u003e\n[![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=E32BUP77SVBA2)\n\n## Licence\n\n```\nThe MIT License (MIT)\n\nCopyright (c) 2015 Douglas Nassif Roma Junior\n```\n\nSee the full [licence file](https://github.com/douglasjunior/AndroidBluetoothLibrary/blob/master/LICENSE).\n\n","funding_links":["https://github.com/sponsors/douglasjunior","https://patreon.com/douglasjunior","paypal.me/douglasnassif","https://www.patreon.com/douglasjunior","https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=E32BUP77SVBA2"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdouglasjunior%2Fandroidbluetoothlibrary","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdouglasjunior%2Fandroidbluetoothlibrary","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdouglasjunior%2Fandroidbluetoothlibrary/lists"}