Android-Scanner-Compat-Library icon indicating copy to clipboard operation
Android-Scanner-Compat-Library copied to clipboard

No scan results - Pixel 6a Android 13

Open johnnyzen opened this issue 2 years ago • 3 comments

Hi, during testing devices, I am not getting any results for a Pixel 6a on Android 13.

Working fine on: Samsung - Galaxy Fold Android 13, Samsung - (industry phone) Android 12 Pixel 4 - Android 12 and Android 13.

I am aware of many issues at the moment with pixel / android 13 and bluetooth.

Just wondered if anyone else having same issue.

Thanks.

johnnyzen avatar Mar 14 '23 16:03 johnnyzen

I'm having the same issue on a Pixel 7 v 13: onScannerRegistered() - status=0 scannerId=3 mScannerId=0 shows up in the log and everything appears to be working, but no success or error callbacks are ever fired.

atlantis avatar May 02 '23 22:05 atlantis

In android 13, after adding below line is working fine for me.

<uses-permission android:name="android.permission.BLUETOOTH_SCAN"
        android:usesPermissionFlags="neverForLocation"
        tools:targetApi="s"/>

Lumberjack100 avatar May 15 '23 02:05 Lumberjack100

any update ?

found follow code about No scan results in Samsung S22 Ultra Android 13

class ScanResponse {
    var localName: String? = null
}

fun parseName(scanResult: ScanResult): String? {
    if (Build.VERSION.SDK_INT >= 33) {
        // Android 13
        scanResult.scanRecord?.let { scanRecord ->
            if (scanRecord.deviceName != null) {
                return scanRecord.deviceName
            } else {
                // If deviceName is null, parse the scan response packet for better compatibility
                scanRecord.bytes?.let { rawBytes ->
                    // rawBytes total length is 62 bytes, the first half is 31 bytes of advertising data,
                    // and the second half is 31 bytes of scan response data
                    val scanResponse = parseScanResponse(rawBytes, 31)
                    return scanResponse.localName
                }
            }
        }
    }

    return scanResult.scanRecord?.deviceName
}

@TargetApi(33)
fun parseScanResponse(bytes: ByteArray, start: Int): ScanResponse {
    val scanResponse = ScanResponse()
    var pos = start
    var len = bytes[pos].toInt().and(0xff)
    var dataType: Int
    var data: ByteArray
    while (len > 0) {
        dataType = bytes[++pos].toInt().and(0xff)
        data = bytes.copyOfRange(pos, pos + len - 1)
        when (dataType) {
            ScanRecord.DATA_TYPE_LOCAL_NAME_SHORT,
            ScanRecord.DATA_TYPE_LOCAL_NAME_COMPLETE -> {
                val localName = String(data)
                println("localName: $localName")
                scanResponse.localName = localName
            }
            // If you need to parse other data, add other DATA_TYPE_xxx as needed
            else -> {
                println("Data Type: 0x${String.format("%02X", dataType)}, Data: $data")
            }
        }
        pos += len - 1
        len = bytes[pos].toInt().and(0xff)
    }
    return scanResponse
}

Yongle-Fu avatar Sep 20 '23 07:09 Yongle-Fu