Thursday, 30 September 2021

How to avoid using Chooser for Companion Device Pairing

I am using this example https://developer.android.com/guide/topics/connectivity/companion-device-pairing to avoid asking location permissions when performing BLE scans. Is there any way to avoid launching the Chooser and stay in the app?

Basically, need to intercept the IntentSender when onDeviceFound is called:

deviceManager.associate(pairingRequest, object: CompanionDeviceManager.Callback() {
    // Called when a device is found. Launch the IntentSender so the user
    // can select the device they want to pair with.
    override fun onDeviceFound(chooserLauncher: IntentSender) {
        startIntentSenderForResult(chooserLauncher,
            SELECT_DEVICE_REQUEST_CODE, null, 0, 0, 0)
    }

    override fun onFailure(error: CharSequence?) {
        // Handle the failure.
    }
}, null)

Thank you.



from How to avoid using Chooser for Companion Device Pairing

No comments:

Post a Comment