{"id":27255242,"url":"https://github.com/harryjph/android-bluetooth-serial","last_synced_at":"2026-03-09T15:02:24.354Z","repository":{"id":48011306,"uuid":"133871871","full_name":"harryjph/android-bluetooth-serial","owner":"harryjph","description":"A library for Android to simplify basic serial communication over Bluetooth, for example when communicating with Arduinos.","archived":false,"fork":false,"pushed_at":"2022-11-01T15:07:09.000Z","size":174,"stargazers_count":170,"open_issues_count":11,"forks_count":62,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-05-05T05:32:07.431Z","etag":null,"topics":["android","android-arduino","android-arduino-remote","android-bluetooth","android-bluetooth-device","android-bluetooth-serial","android-library","arduino","arduino-bluetooth","arduino-bluetooth-android","arduinos","bluetooth","bluetooth-arduino","bluetooth-connection","java","kotlin","kotlin-android","library","serial","serial-communication"],"latest_commit_sha":null,"homepage":null,"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/harryjph.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},"funding":{"github":"harry1453"}},"created_at":"2018-05-17T21:48:14.000Z","updated_at":"2024-05-03T00:38:59.000Z","dependencies_parsed_at":"2023-01-21T05:03:48.920Z","dependency_job_id":null,"html_url":"https://github.com/harryjph/android-bluetooth-serial","commit_stats":null,"previous_names":["harryjph/android-bluetooth-serial","harry1453/android-bluetooth-serial"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harryjph%2Fandroid-bluetooth-serial","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harryjph%2Fandroid-bluetooth-serial/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harryjph%2Fandroid-bluetooth-serial/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harryjph%2Fandroid-bluetooth-serial/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/harryjph","download_url":"https://codeload.github.com/harryjph/android-bluetooth-serial/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248328213,"owners_count":21085269,"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-arduino","android-arduino-remote","android-bluetooth","android-bluetooth-device","android-bluetooth-serial","android-library","arduino","arduino-bluetooth","arduino-bluetooth-android","arduinos","bluetooth","bluetooth-arduino","bluetooth-connection","java","kotlin","kotlin-android","library","serial","serial-communication"],"created_at":"2025-04-11T02:19:08.417Z","updated_at":"2026-03-09T15:02:19.302Z","avatar_url":"https://github.com/harryjph.png","language":"Java","readme":"# android-bluetooth-serial\n\n[![Build Status](https://travis-ci.com/harry1453/android-bluetooth-serial.svg?branch=master)](https://travis-ci.com/harry1453/android-bluetooth-serial)\n\nA library for Android to simplify basic serial communication over Bluetooth, for example when communicating with Arduinos.\n\n## How to include the library\n\n[![JitPack](https://jitpack.io/v/harry1453/android-bluetooth-serial.svg)](https://jitpack.io/#harry1453/android-bluetooth-serial)\n\n**Gradle**\n\n- **Project level `build.gradle`**\n```gradle\nallprojects {\n    repositories {\n        maven { url 'https://jitpack.io' }\n    }\n}\n```\n- **App level `build.gradle`**\n```gradle\ndependencies {\n    implementation 'com.github.harry1453:android-bluetooth-serial:v1.1'\n    \n    // RxJava is also required.\n    implementation 'io.reactivex.rxjava2:rxjava:2.1.12'\n    implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'\n}\n```\n\n## Using the library\n\nPlease see the `demoApplication` directory for a fully-featured demo app.\n\n1. Declare your `BluetoothManager` (Make sure to include the library `BluetoothManager`, not the Android one):\n\n```JAVA\nimport com.harrysoft.androidbluetoothserial.BluetoothManager;\n```\n\nYour Activity's `onCreate()`:\n\n```JAVA\n// Setup our BluetoothManager\nBluetoothManager bluetoothManager = BluetoothManager.getInstance();\nif (bluetoothManager == null) {\n    // Bluetooth unavailable on this device :( tell the user\n    Toast.makeText(context, \"Bluetooth not available.\", Toast.LENGTH_LONG).show(); // Replace context with your context instance.\n    finish();\n}\n```\n\n2. Get the list of paired devices:\n\n```JAVA\nCollection\u003cBluetoothDevice\u003e pairedDevices = bluetoothManager.getPairedDevices();\nfor (BluetoothDevice device : pairedDevices) {\n    Log.d(\"My Bluetooth App\", \"Device name: \" + device.getName());\n    Log.d(\"My Bluetooth App\", \"Device MAC Address: \" + device.getAddress());\n}\n```\n\n3. Select a device you want to connect to from the list and fetch its MAC Address.\n\n4. Connect to the device and send/receive messages:\n\n```JAVA\nimport com.harrysoft.androidbluetoothserial.BluetoothSerialDevice;\n```\n\n```JAVA\nprivate SimpleBluetoothDeviceInterface deviceInterface;\n\nprivate void connectDevice(String mac) {\n    bluetoothManager.openSerialDevice(mac)\n            .subscribeOn(Schedulers.io())\n            .observeOn(AndroidSchedulers.mainThread())\n            .subscribe(this::onConnected, this::onError);\n}\n\nprivate void onConnected(BluetoothSerialDevice connectedDevice) {\n    // You are now connected to this device!\n    // Here you may want to retain an instance to your device:\n    deviceInterface = connectedDevice.toSimpleDeviceInterface();\n    \n    // Listen to bluetooth events\n    deviceInterface.setListeners(this::onMessageReceived, this::onMessageSent, this::onError);\n    \n    // Let's send a message:\n    deviceInterface.sendMessage(\"Hello world!\");\n}\n\nprivate void onMessageSent(String message) {\n    // We sent a message! Handle it here.\n    Toast.makeText(context, \"Sent a message! Message was: \" + message, Toast.LENGTH_LONG).show(); // Replace context with your context instance.\n}\n\nprivate void onMessageReceived(String message) {\n    // We received a message! Handle it here.\n    Toast.makeText(context, \"Received a message! Message was: \" + message, Toast.LENGTH_LONG).show(); // Replace context with your context instance.\n}\n\nprivate void onError(Throwable error) {\n    // Handle the error\n}\n```\n\n5. Disconnect the device:\n```JAVA\n// Please remember to destroy your instance after closing as it will no longer function!\n\n// Disconnect one device\nbluetoothManager.closeDevice(macAddress); // Close by mac\n// OR\nbluetoothManager.closeDevice(connectedDevice); // Close by device instance\n// OR\nbluetoothManager.closeDevice(deviceInterface); // Close by interface instance\n\n// Disconnect all devices\nbluetoothManager.close();\n```\n","funding_links":["https://github.com/sponsors/harry1453"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharryjph%2Fandroid-bluetooth-serial","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fharryjph%2Fandroid-bluetooth-serial","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharryjph%2Fandroid-bluetooth-serial/lists"}