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

When scanning by pendingIntent with optional extra, extra of broadcastreceiver intent is overwritten, so EXTRA_LIST_SCAN_RESULT data is lost. #117

Open
jeddchoi opened this issue Mar 24, 2022 · 1 comment

Comments

@jeddchoi
Copy link

// in BroadcastReceiver(MyReceiver)
override fun onReceive(context: Context, intent: Intent) {
        Log.e(TAG, "onReceive: ${intent.extras?.getInt("my.extra.data")}")
        Log.e(TAG, "onReceive: ${intent.action}")
        Log.e(TAG, "onReceive: ${intent.hasExtra(BluetoothLeScanner.EXTRA_LIST_SCAN_RESULT)}")
        Log.e(TAG, "onReceive: ${intent.getParcelableArrayListExtra<ScanResult>(BluetoothLeScanner.EXTRA_LIST_SCAN_RESULT)?.size}")
}
  1. start scan without extra
        requestCode++

        val intent = Intent(context, MyReceiver::class.java) // explicit intent

        intent.action = ACTION_FOUND_DEVICE

        val pendingIntent = PendingIntent.getBroadcast(
            context,
            requestCode,
            intent,
            PendingIntent.FLAG_UPDATE_CURRENT
        )

        BluetoothLeScannerCompat.getScanner().startScan(
            getScanFilter(),
            getScanSettings(),
            context,
            pendingIntent,
            requestCode
        )

Result(Logs in MyReceiver) :

onReceive: 0
onReceive: ACTION_FOUND_DEVICE
onReceive: true
onReceive: 1

As you can see, extra of EXTRA_LIST_SCAN_RESULT exist and
extra of "my.extra.data" is 0(which is default value of Int).

  1. start scan with extra data
        requestCode++

        val intent = Intent(context, MyReceiver::class.java) // explicit intent

        intent.action = ACTION_FOUND_DEVICE
        intent.putExtra("my.extra.data", 100) // INPUT OPTIONAL EXTRA

        val pendingIntent = PendingIntent.getBroadcast(
            context,
            requestCode,
            intent,
            PendingIntent.FLAG_UPDATE_CURRENT
        )

        BluetoothLeScannerCompat.getScanner().startScan(
            getScanFilter(),
            getScanSettings(),
            context,
            pendingIntent,
            requestCode
        )

Result(Logs in MyReceiver) :

onReceive: 100
onReceive: ACTION_FOUND_DEVICE
onReceive: false
onReceive: null

Extra of EXTRA_LIST_SCAN_RESULT is null
and extra of "my.extra.data" is 100(which is value I put on starting scan).

How can I put custom extra?
In addition, when I tried with immutable request code, result was same.

@jeddchoi
Copy link
Author

I think #66 is related with this

@jeddchoi jeddchoi changed the title When scanning by pendingIntent with extra, extra of broadcastreceiver intent is overwritten, so EXTRA_LIST_SCAN_RESULT data is lost. When scanning by pendingIntent with optional extra, extra of broadcastreceiver intent is overwritten, so EXTRA_LIST_SCAN_RESULT data is lost. Mar 24, 2022
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

1 participant