# bluetooth **Repository Path**: mahongquan/bluetooth ## Basic Information - **Project Name**: bluetooth - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-11-28 - **Last Updated**: 2026-11-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # BT Bridge - Android <-> PC over Bluetooth Bidirectional text messaging and file transfer over Bluetooth Classic (RFCOMM / Serial Port Profile). Both apps use the same service UUID `b7a7c6a0-7f4b-11ee-b962-0242ac120002` and exchange framed messages: `T \n` + UTF-8 text, or `F \n` + name bytes + raw file bytes. ## Files | Path | Description | | --- | --- | | `BTBridge.apk` | Install this on the Android phone | | `build-android.ps1` | Rebuild the APK | | `pc/pyqt/bt_bridge_qt.py` | PyQt5 + QtBluetooth desktop app (both roles) | | `run-pc-pyqt.ps1` | Launch the PyQt desktop app | | `pc/python/bt_bridge.py` | Python desktop app (no third-party packages) | | `run-pc-python.ps1` | Launch the Python desktop app | | `pc/out/BluetoothBridge.jar` | Alternative Java desktop app (BlueCove included) | | `build-pc.ps1` | Rebuild the Java desktop jar | | `run-pc.ps1` | Launch the Java desktop app | | `android/src/.../MainActivity.java` | Android app source | | `pc/src/.../BluetoothPc.java` | Java desktop app source | Requires JDK at `c:\ma\jdk-25.0.2` and Android SDK at `c:\ma\android_sdk` (build-tools 36.0.0, platform android-36). ## Build ```powershell powershell -ExecutionPolicy Bypass -File build-android.ps1 # Python PC apps need no build step; run either directly: powershell -ExecutionPolicy Bypass -File run-pc-pyqt.ps1 powershell -ExecutionPolicy Bypass -File run-pc-python.ps1 # Optional Java PC app: powershell -ExecutionPolicy Bypass -File build-pc.ps1 ``` ## Setup 1. Turn on Bluetooth on both devices. 2. Pair the phone and the PC in Windows Bluetooth settings first. On the phone, accept the pairing request. 3. Install `BTBridge.apk` on the phone (allow "Install unknown apps" for the file manager you open it from). 4. On the phone, open BT Bridge and grant the Bluetooth / Nearby devices permissions. The Python app needs only the standard library: Windows Python exposes Bluetooth RFCOMM through `socket.AF_BLUETOOTH`. The optional Java app uses the 64-bit BlueCove fork (`io.ultreia:bluecove:2.1.1`). Either way a Bluetooth adapter must be present and paired with the phone. ## Usage ### Option 0 - PyQt5 PC app (both roles, recommended if PyQt is installed) 1. Run `powershell -ExecutionPolicy Bypass -File run-pc-pyqt.ps1`. 2. Client role: put the phone in **Listen (server)** mode, click **Discover Phones**, pick the phone, then click **Connect**. Qt resolves the service by UUID, so no RFCOMM channel number is needed. 3. Server role: click **Start Server** on the PC, then tap the PC in the phone's paired list. 4. **Send** transfers text; **Send File** transfers a file. Incoming files are saved to `Downloads\BTBridge`. Windows Qt Bluetooth notes: only previously paired devices are found, custom SDP fields are filled by Qt, and OBEX push is unavailable. ### Option 1 - Python PC app (phone listens, PC connects) 1. On the phone tap **Listen (server)**. The log prints the phone's Bluetooth address and, on Android 10+, an `RFCOMM channel: N` line. 2. Run `powershell -ExecutionPolicy Bypass -File run-pc-python.ps1`. 3. Enter the phone's address (e.g. `AA:BB:CC:DD:EE:FF`) and the channel number, then click **Connect**. The values are remembered in `pc/python/bt_bridge_config.json`. 4. Type and click **Send**, or click **Send File** to transfer a file. Incoming text and files appear in the log; files are saved to `Downloads\BTBridge`. 5. The Python app is client-only. To have the PC listen instead, use the Java app (Option 2). ### Option 2 - Java PC app, PC listens, phone connects 1. Run `powershell -ExecutionPolicy Bypass -File run-pc.ps1` and click **Start Server**. It becomes discoverable and waits. 2. On the phone tap **Refresh** to load the paired-device list. 3. Tap the PC in the list. The status changes to `connected`. 4. Type in either app and press **Send** (or Enter). Received lines appear as `< message`, sent lines as `> message`. 5. To send a file: tap **File** on the phone and pick a document, or click **Send File** on the PC and choose a file. The receiver saves it to `Download/BTBridge` on the phone or `Downloads\BTBridge` in your user folder on the PC and logs the path. ### Option 3 - Java PC app, phone listens, PC connects 1. On the phone tap **Listen (server)**. The phone becomes discoverable for 5 minutes. The log shows the phone's Bluetooth MAC address. 2. On the PC click **Find & Connect** and pick the phone from the list. If discovery fails, click **Manual MAC** and enter the address shown in the phone log. 3. Exchange messages. **Disconnect** closes the link. In client mode you can connect to a different device by tapping it. ## Notes - Bluetooth Classic is required (not BLE). Both devices must support SPP; virtually all phones and PCs do. - The phone shows its own address in the log so it can be entered manually on the PC. - Messages are single lines; newlines typed in the input box are replaced with spaces. - Files up to 100 MB are supported. Do not send two files at exactly the same time from both ends (frames are written atomically per side, but a full-duplex race is still possible). - Android 12+ uses `BLUETOOTH_CONNECT` / `BLUETOOTH_SCAN`; Android 11 and below use the legacy Bluetooth plus location and storage permissions. - The phone prints the RFCOMM channel only on Android 10+; on older versions use the Java PC app, which discovers the service by UUID. - The APK and either PC app must use the framed protocol - the text-only version from the first build is not compatible.