Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No scan results - Pixel 6a Android 13 #135

Open
johnnyzen opened this issue Mar 14, 2023 · 3 comments
Open

No scan results - Pixel 6a Android 13 #135

johnnyzen opened this issue Mar 14, 2023 · 3 comments

Comments

@johnnyzen
Copy link

johnnyzen commented Mar 14, 2023

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.

@atlantis
Copy link

atlantis commented May 2, 2023

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.

@Lumberjack100
Copy link

Lumberjack100 commented May 15, 2023

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"/>

@Yongle-Fu
Copy link

Yongle-Fu commented Sep 20, 2023

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
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants