#aneeb_code
1 messages · Page 1 of 1 (latest)
đź‘‹ Welcome to your new thread!
⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
đź”— This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1423573339452084324
📝 Have more to share? Add more details, code, screenshots, videos, etc. below.
Hi there, can you tell me more about " discovery flow doesn’t always stick to that saved reader." ?
https://docs.stripe.com/terminal/payments/connect-reader?terminal-sdk-platform=android&reader-type=bluetooth#automatic-reconnection-on-application-start btw we have a doc showing the steps to automatically connect a reader.
okay sure let me check that out
also i provide the details what i have already did and what i want to achieve
I’m seeing an intermittent issue where the app discovers multiple Bluetooth readers at discovery time and sometimes connects to a different reader than the one previously paired. We store the reader’s serial in local storage, but the discovery flow doesn’t always stick to that saved reader.
" connects to a different reader than the one previously paired. " -> did your app call terminal.connectReader to connect to that reader?
we call connect card reader after ddiscovering the card reader
hi! I'm taking over this thread.
private val discoveryListener by lazy {
object : DiscoveryListener {
override fun onUpdateDiscoveredReaders(readers: List<Reader>) {
// 1) Publish list to UI
_discoveredReaders.value = readers
/**
No Available Readers
**/
if (readers.isEmpty()) {
updateTerminalState(TerminalState.Exception("No readers available!"))
} else {
/**
Discovered Readers
**/
updateTerminalState(
TerminalState.Discovered(
message = "Discovered: ${
readers.map {
"DeviceName=>${it.deviceType.deviceName},Simulated=>${it.isSimulated},SN=>${it.serialNumber},Reader Name=>${it.deviceType.name}IsUSBConnected=>${it.isUsbConnected}"
}
}"
)
)
}
val savedSerial = getPreferredReader()
if (savedSerial != null) {
// Next time → look for saved reader
val matched = readers.firstOrNull { it.serialNumber.equals(savedSerial, true) }
if (matched != null) {
connectReader(matched)
} else {
updateTerminalState(TerminalState.Exception("Previously connected reader ($savedSerial) not found. Please make it available."))
}
}
}
}
}
this is the code i am using for the discovery and connecting to card reader
did you follow the doc here? https://docs.stripe.com/terminal/payments/connect-reader?terminal-sdk-platform=android&reader-type=bluetooth#connect-reader
because when you call cnnectReader, it's your code that decides to which readers it connects to: https://stripe.dev/stripe-terminal-android/core/com.stripe.stripeterminal/-terminal/connect-reader.html
yes i follow the same, my question is why it is going on discovering the the new card reader when it is already paired to one
can you share your code that calls terminal.connectReader?
private val discoveryListener by lazy {
object : DiscoveryListener {
override fun onUpdateDiscoveredReaders(readers: List<Reader>) {
// 1) Publish list to UI
_discoveredReaders.value = readers
/**
No Available Readers
**/
if (readers.isEmpty()) {
updateTerminalState(TerminalState.Exception("No readers available!"))
} else {
/**
Discovered Readers
**/
updateTerminalState(
TerminalState.Discovered(
message = "Discovered: ${
readers.map {
"DeviceName=>${it.deviceType.deviceName},Simulated=>${it.isSimulated},SN=>${it.serialNumber},Reader Name=>${it.deviceType.name}IsUSBConnected=>${it.isUsbConnected}"
}
}"
)
)
}
val savedSerial = getPreferredReader()
if (savedSerial != null) {
// Next time → look for saved reader
val matched = readers.firstOrNull { it.serialNumber.equals(savedSerial, true) }
if (matched != null) {
connectReader(matched)
} else {
updateTerminalState(TerminalState.Exception("Previously connected reader ($savedSerial) not found. Please make it available."))
}
}
}
}
}
private fun connectReader(reader: Reader) {
val connectionConfig = ConnectionConfiguration.BluetoothConnectionConfiguration(
locationId = userInfo.value?.locationId.default,
autoReconnectOnUnexpectedDisconnect = true,
bluetoothReaderListener = mobileReaderListener
)
Terminal.getInstance().connectReader(
reader = reader,
config = connectionConfig,
connectionCallback = readerCallback
)
}
well you can see in your code that you are selecting the reader yourself:
Terminal.getInstance().connectReader(
reader = reader,
so next steps is to debug your code to see where reader is set.
brother connect part is not my concern right now, i am concerned about the discovery part that it is discovering different readers other than the already discovered and paired reader
override fun onUpdateDiscoveredReaders(readers: List<Reader>) {
val savedSerial = getPreferredReader()
if (savedSerial != null) {
// Next time → look for saved reader
val matched = readers.firstOrNull { it.serialNumber.equals(savedSerial, true) }
if (matched != null) {
connectReader(matched)
} else {
updateTerminalState(TerminalState.Exception("Previously connected reader ($savedSerial) not found. Please make it available."))
}
}
}
see this code for reference
in this case, can you share your code that is calling the discoverReaders method? I don't see it in everything you shared so far.
/**
Discovering readers via Bluetooth
* **/
@SuppressLint("MissingPermission")
private fun discoverBluetoothReaders() {
Terminal
.getInstance()
.discoverReaders(
config = bluetoothDiscoveryConfig,
discoveryListener = discoveryListener,
callback = discoveryCallback
)
}
thanks! your code looks correct.
Expected: if a saved reader serial exists, discovery should prefer — and immediately attempt to connect to — that reader only.
why do you have that expectation? was it working like this before? or did you see it mentioned in the documentation somewhere?
if you want to reconnect to a previously connected reader, that's a logic you should implement on your end.
can you help me with that, what logic should i write for that
what logic do you want exactly? you want to always connect to the same reader (and ignore the other readers)?
yes
using the serial number (like you already do) seem like a good idea.