使用Nearby 12.0.1与Android Things 1.0触发8007蓝牙错误求助
STATUS_BLUETOOTH_ERROR (8007) on Android Things + Nearby Connections 2.0 Hey there, sorry to hear you're stuck with this frustrating Bluetooth error on your Raspberry Pi 3 Model B. Let's dig into what's going on here and try some targeted fixes based on the details you shared.
First, let's recap the key clues from your issue:
- Your old setup (5/8 system image + old APK) works perfectly
- New system image + any APK (old or new) throws
com.google.android.gms.common.api.ApiException:8007 STATUS_BLUETOOTH_ERROR - Logcat mentions "无法监听入站连接" (can't listen for incoming connections)
This tells us the problem is almost certainly tied to changes in the new Android Things system image—either in the Bluetooth stack, Google Play Services compatibility, or system-level permissions. Here's what to try next:
1. Validate System Image Version Differences
Head over to your Android Things Console and note the exact version number of the new problematic image. Compare it to the 5/8 working image to see if there are explicit Bluetooth or Google Play Services updates listed.
If possible, roll back to the 5/8 image and test a freshly compiled version of your APK. If that works, the issue is definitely a compatibility gap between the new system image and your outdated Nearby Connections API version.
2. Check Bluetooth Hardware & Service Health
- Use ADB to inspect the Bluetooth service status:
Look for lines indicating initialization failures, permission denials, or disabled hardware.adb shell dumpsys bluetooth_manager - Restart the Bluetooth service to rule out transient glitches:
# Turn off Bluetooth adb shell service call bluetooth_manager 6 # Turn it back on adb shell service call bluetooth_manager 7 - Verify your APK has all required permissions in the manifest:
On the new system image, double-check that these permissions are actually granted (Android Things sometimes adjusts permission behavior in updates).<uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
3. Upgrade Your Nearby Connections API Version
You're using com.google.android.gms:play-services-nearby:12.0.1—this is a very old version (circa 2018). The new Android Things image likely has an updated version of Google Play Services, which can break compatibility with outdated Nearby APIs.
Try upgrading to a newer, Android Things 1.0-compatible version. Aim for a middle-ground release like 17.0.0 (avoid the absolute latest versions, as Android Things 1.0 has limited support for modern Play Services). Rebuild your APK and test on the new system image.
4. Hardening Nearby Initialization & Error Handling
Add explicit checks for Bluetooth availability before starting advertising/discovery:
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (bluetoothAdapter == null) { // Handle no Bluetooth hardware Log.e(TAG, "Bluetooth not supported on this device"); return; } if (!bluetoothAdapter.isEnabled()) { // Request Bluetooth enable (or handle it programmatically) Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); }
When catching the ApiException, log the full error details to get more context:
catch (ApiException e) { Log.e(TAG, "Nearby error: " + e.getMessage() + ", status code: " + e.getStatusCode()); }
This might reveal specific issues like a blocked port, uninitialized Bluetooth stack, or missing service bindings.
5. Inspect System-Level Bluetooth Configurations
New system images sometimes tweak default Bluetooth settings. Compare these properties between your working and broken images:
adb shell getprop bluetooth.*
Look for differences in properties like persist.bluetooth.enable, bluetooth.scan.mode, or bluetooth.ble.enabled. If you spot a relevant change, you can modify it temporarily (with root access) to test:
adb shell setprop persist.bluetooth.enable 1 adb reboot
内容的提问来源于stack exchange,提问作者Koustuv Ganguly

