You are here: Forum Home → ANT Developers Forums → ANT in Mobile Phones → Thread
val multiDeviceSearch = MultiDeviceSearch(context, devicesType, callbacks, rssiCallback)
val callbacks = object : SearchCallbacks {
override fun onSearchStarted(p0: MultiDeviceSearch.RssiSupport?) {
}
override fun onDeviceFound(p0: MultiDeviceSearchResult?) {
p0?.let {
onNewDeviceFound(p0)
}
}
override fun onSearchStopped(p0: RequestAccessResult?) {
}
}
private fun onNewDeviceFound(multiDeviceSearchResult: MultiDeviceSearchResult) {
val id = multiDeviceSearchResult.antDeviceNumber.toString()
val name =
"${multiDeviceSearchResult.deviceDisplayName}_${multiDeviceSearchResult.antDeviceType}"
val device = when (multiDeviceSearchResult.antDeviceType) {
DeviceType.FITNESS_EQUIPMENT -> {
AntFitnessEquipmentDevice(
name = name,
id = id,
multiDeviceSearchResult = multiDeviceSearchResult,
context = context
)
}
else -> {
//nothing for now
null
}
}
}
class AntFitnessEquipmentDevice(
override val name: String,
override val id: String,
override val multiDeviceSearchResult: MultiDeviceSearch.MultiDeviceSearchResult,
private val context: Context
) {
private var fitnessEquipmentPcc: AntPlusFitnessEquipmentPcc? = null
private var handle: PccReleaseHandle<AntPlusFitnessEquipmentPcc>? = null
var equipmentType: AntPlusFitnessEquipmentPcc.EquipmentType = UNRECOGNIZED
//region Parent Methods
override fun requestAccess() {
handle?.close()
handle = AntPlusFitnessEquipmentPcc.requestNewOpenAccess(
context,
multiDeviceSearchResult.antDeviceNumber,
0,
resultReceiver,
stateChangeReceiver,
fitnessEquipmentStateReceiver
)
}
override fun release() {
fitnessEquipmentPcc?.releaseAccess()
}
override fun close() {
handle?.close()
}
//endregion
//region Private Methods
private fun onPcc() {
fitnessEquipmentPcc?.let {
subscribeCommonReceiver(it)
}
}
//endregion
//region Callback
// AntPlusBikeCadencePcc var1,
// RequestAccessResult var2,
// DeviceState var3
private val resultReceiver =
AntPluginPcc.IPluginAccessResultReceiver<AntPlusFitnessEquipmentPcc> { pcc, requestAccessResult, deviceState ->
when (requestAccessResult) {
SUCCESS -> {
fitnessEquipmentPcc = pcc
actualState = deviceState
onPcc()
}
DEPENDENCY_NOT_INSTALLED -> {
// TODO alert??
}
SEARCH_TIMEOUT -> {
retryRequestAccess()
}
// USER_CANCELLED -> {}
// CHANNEL_NOT_AVAILABLE -> {}
// OTHER_FAILURE -> {}
// DEVICE_ALREADY_IN_USE -> {}
// ALREADY_SUBSCRIBED -> {}
// BAD_PARAMS -> {}
// ADAPTER_NOT_DETECTED -> {}
// UNRECOGNIZED -> {}
else -> {
// nothing
}
}
}
private val stateChangeReceiver = IDeviceStateChangeReceiver { deviceState ->
actualState = deviceState
onChangeState(deviceState)
}
// estTimestamp: Long,
// eventFlags: EnumSet<EventFlag>?,
// equipmentType: AntPlusFitnessEquipmentPcc.EquipmentType?,
// equipmentState: AntPlusFitnessEquipmentPcc.EquipmentState?
private val fitnessEquipmentStateReceiver =
AntPlusFitnessEquipmentPcc.IFitnessEquipmentStateReceiver { _, _, equipmentType, equipmentState ->
fitnessEquipmentPcc?.let { pcc ->
this.equipmentType = equipmentType
}
}
// estTimestamp: Long,
// eventFlags: EnumSet<EventFlag>?,
// capabilities: AntPlusFitnessEquipmentPcc.Capabilities?
private val capabilitiesReceiver =
AntPlusFitnessEquipmentPcc.ICapabilitiesReceiver { _, _, capabilities ->
}
//endregion
}
xml
<uses-permission android:name="android.permission.USB_PERMISSION" />
happy wheelsHello, I think you should check USB Permissions: Make sure that your Android app has the necessary permissions to access USB devices. In your app's manifest file, include the following permission:
xml
<uses-permission android:name="android.permission.USB_PERMISSION" />
Additionally, you may need to request USB permission at runtime before accessing the USB ANT stick
tifa sexdollHello, I think you should check USB Permissions: Make sure that your Android app has the necessary permissions to access USB devices. In your app's manifest file, include the following permission:
xml
<uses-permission android:name="android.permission.USB_PERMISSION" />
Additionally, you may need to request USB permission at runtime before accessing the USB ANT stick