I was unable to do so, so I examined the source code of System.Tether.Manager (the same goes for System.Tether.AppProfile) in detail, and most likely I found the cause of the problem.
When the TetheringManager.DiscoverManagers command is executed, no event occurs, but if the TetheringManager.RemoteManagers statement is executed after this command, all surrounding devices are listed.
The problem is that the library uses the TThread.Synchronize function to synchronize events. This feature requires a main UI thread for its functionality. This functionality does not have an android service. Therefore, the event update fails every time (for example, onEndManagersDiscovery). The library is not intended for use in the android service.
procedure TTetheringManager.DoEndManagersDiscovery(const ARemoteManagers: TTetheringManagerInfoList);
begin
RegisterManagers(ARemoteManagers);
if Assigned(FOnEndManagersDiscovery) then
begin
if SynchronizeEvents then
TThread.Synchronize(nil,
procedure
begin
FOnEndManagersDiscovery(Self, ARemoteManagers);
end)
else
FOnEndManagersDiscovery(Self, ARemoteManagers);
end
end;
Interestingly, for example, the OnRequestStorage event works because it uses directly FOnRequestStorage(Self, AStorage) instead of TThread.Synchronize to update the event.
procedure TTetheringManager.DoRequestStorage(var AStorage: TTetheringCustomStorage);
begin
AStorage := nil;
if Assigned(FOnRequestStorage) then
FOnRequestStorage(Self, AStorage);
end;
Update: Now I have found that the easiest way to solve this problem will be to disable SynchroniyeEvents for booth TetheringManager and TetheringAppProfile.