You are here: Forum Home → ANT Developers Forums → ANT in Mobile Phones → Thread
public void searchForANTS(){
Log.d(TAG, "1 Search for ants..");
/*AntPlusHeartRatePcc.requestAccess(defaultActivity,defaultActivity.getBaseContext(), pluginAccess, deviceStateChange);*/
hrScanCtrl = AntPlusHeartRatePcc.requestAsyncScanController(this.defaultActivity, 10,
new IAsyncScanResultReceiver()
{
@Override
public void onSearchStopped(RequestAccessResult reasonStopped)
{
//The triggers calling this function use the same codes and require the same actions as those received by the standard access result receiver
//base_IPluginAccessResultReceiver.onResultReceived(null, reasonStopped, DeviceState.DEAD);
Log.d(TAG, "ant+ device.dead");
}
@Override
public void onSearchResult(final AsyncScanResultDeviceInfo deviceFound)
{
for(AsyncScanResultDeviceInfo i: mScannedDeviceInfos)
{
//The current implementation of the async scan will reset it's ignore list every 30s,
//So we have to handle checking for duplicates in our list if we run longer than that
if(i.getAntDeviceNumber() == deviceFound.getAntDeviceNumber())
{
//Found already connected device, ignore
Log.d(TAG, "ant+ found connected device");
requestConnectToResult(deviceFound);
return;
}
}
//We split up devices already connected to the plugin from un-connected devices to make this information more visible to the user,
//since the user most likely wants to be aware of which device they are already using in another app
if(deviceFound.isAlreadyConnected())
{
mAlreadyConnectedDeviceInfos.add(deviceFound);
//adapter_connDevNameList.add(deviceFound.getDeviceDisplayName());
//adapter_connDevNameList.notifyDataSetChanged();
Log.d(TAG, "ant+ already connected " + deviceFound.getDeviceDisplayName());
}
else
{
mScannedDeviceInfos.add(deviceFound);
// adapter_devNameList.add(deviceFound.getDeviceDisplayName());
//adapter_devNameList.notifyDataSetChanged();
Log.d(TAG, "ant+ unpaired device found " + deviceFound.getDeviceDisplayName());
requestConnectToResult(deviceFound);
}
}
});
Log.d(TAG, "ANT+ passed here");
}
protected void requestConnectToResult(final AsyncScanResultDeviceInfo asyncScanResultDeviceInfo)
{
Log.d(TAG, "Connecting to " + asyncScanResultDeviceInfo.getDeviceDisplayName());
hrScanCtrl.requestDeviceAccess(asyncScanResultDeviceInfo,
new IPluginAccessResultReceiver<AntPlusHeartRatePcc>()
{
@Override
public void onResultReceived(AntPlusHeartRatePcc result,
RequestAccessResult resultCode, DeviceState initialDeviceState)
{
if(resultCode == RequestAccessResult.SEARCH_TIMEOUT)
{
//On a connection timeout the scan automatically resumes, so we inform the user, and go back to scanning
Log.d(TAG, "Scanning for heart rate devices asynchronously...");
}
else
{
//Otherwise the results, including SUCCESS, behave the same as
pluginAccess.onResultReceived(result, resultCode, initialDeviceState);
}
}
}, deviceStateChange);
}