Sorry, you need to enable JavaScript to visit this website.

Connectivity

Connectivity

Services

Services initialization

Maps SDK for Android provides users with interfaces that can be used to manage connection between devices.

To obtain access to this module you will need to add following dependency to your build.gradle file:

implementation("com.tomtom.online:sdk-connectivity-services:2.4292")

Services module gives access to ConnectivityApi interface and PriorityConnectivityApi implementation.
ConnectivityApi is used to manage connections and send data between devices. In addition it also accepts multiple communicators that will be used to send/receive data.

ConnectivityApi provides access to following methods:

  • Connect

  • Disconnect

  • Send(Command)

In order to create an instance use PriorityConnectivityApiBuilder and provide required parameters to it which are:

  • StatusHandler

  • One or more CommunicatorFactory

  • One or more CommandModule

_

ConnectivityApi connectivityApi = new PriorityConnectivityApiBuilder(context)
            .addCommunicator(communicatorFactory1)
            .addCommunicator(communicatorFactory2)
            .addModule(new CommonCommandModule())
            .withStatusHandler(statusHandler)
            .build()
val connectivityApi = PriorityConnectivityApiBuilder(context)
            .addCommunicator(communicatorFactory1)
            .addCommunicator(communicatorFactory2)
            .addModule(CommonCommandModule())
            .withStatusHandler(statusHandler)
            .build()

StatusHandler will be used by ConnectivityApi for notification of an operations status.
To achieve that implement StatusHandler interface or create an ReferenceStatusHandler in the following manner:

protected val statusHandler = ReferenceStatusHandler(
    onReadStatusReady = { communicatorInfo, status -> onReadStatusReady(communicatorInfo, status) },
    onWriteStatusReady = { communicatorInfo, status -> onWriteStatusReady(communicatorInfo, status) },
    onConnectionStatusReady = { communicatorInfo, status -> onConnectionStatusReady(communicatorInfo, status) },
    onDisconnect = { communicatorInfo -> onDisconnect(communicatorInfo) }
)

Communicators

By default, ConnectivityApi does not support any Communicator. Several communicator modules adapt
specific connection type:

  • Bluetooth SPP Server

  • Bluetooth SPP Client

  • Bluetooth Low Energy Server

  • Bluetooth Low Energy Client

Commands

ConnectivityApi allows to send data between devices. The data is represented by Command. By
default, ConnectivityApi does not support any specific Command, therefore support for default commands
needs to be configured manually.

Step 1: To obtain access to default commands module you will need to add following dependency to
your build.gradle file:

implementation("com.tomtom.online:sdk-connectivity-commands:2.4292")

Step 2: Add CommonCommandModule to PriorityConnectivityApiBuilder:

_

ConnectivityApi connectivityApi = new PriorityConnectivityApiBuilder(context)
            .addCommunicator(communicatorFactory)
            .addModule(new CommonCommandModule())
            .withStatusHandler(statusHandler)
            .build()
val connectivityApi = PriorityConnectivityApiBuilder(context)
            .addCommunicator(communicatorFactory)
            .addModule(CommonCommandModule())
            .withStatusHandler(statusHandler)
            .build()

CommandCommonModule will provide proper CommandSerializer, CommandDeserializer and
CommandTypeMappingFactory which are necessary for correct serialization/deserialization of Command

Custom Commands

If you need to send command that common commands module does not support or you wish to use a
different serialization/deserialization/mapping for an existing Command,
you can easily create your own implementation.

Serialization

To provide an serializer for a command create a class that implements the CommandSerializer and
class that implements CommandSerializersFactory which will return map of custom serializers.
Finally pass it to the ConnectivityApiBuilder:

_

ConnectivityApi connectivityApi = new PriorityConnectivityApiBuilder(context)
            .addCommunicator(communicatorFactory)
            .addModule(new CommonCommandModule())
            .addSerializer(new MyCommandSerializersFactory())
            .withStatusHandler(statusHandler)
            .build()
val connectivityApi = PriorityConnectivityApiBuilder(context)
            .addCommunicator(communicatorFactory)
            .addModule(CommonCommandModule())
            .addSerializer(MyCommandSerializersFactory())
            .withStatusHandler(statusHandler)
            .build()

Deserialization

To provide an deserializer for a command create a class that implements the CommandDeserializer
and class that implements CommandDeserializersFactory which will return map of custom deserializers.
Finally pass it to the ConnectivityApiBuilder:

_

ConnectivityApi connectivityApi = new PriorityConnectivityApiBuilder(context)
            .addCommunicator(communicatorFactory)
            .addModule(new CommonCommandModule())
            .addDeserializer(new MyCommandDeserializersFactory())
            .withStatusHandler(statusHandler)
            .build()
val connectivityApi = PriorityConnectivityApiBuilder(context)
            .addCommunicator(communicatorFactory)
            .addModule(CommonCommandModule())
            .addDeserializer(MyCommandDeserializersFactory())
            .withStatusHandler(statusHandler)
            .build()

Mapping

Each of command should have defined header that will be represented by single Short value wrapped
with CommandType. This value is used to recognize specific command during deserialization.

When adding new command or when you wish to provide different CommandType for existing command
you can provide your own mapping by implementing CommandTypeMappingFactory:

_

public class MyCommandTypeMappingFactory implements CommandTypeMappingFactory {
    private static final CommandType MY_COMMAND = new CommandType(0);

    @Override
    public Map<CommandType, Class<? extends Command>> create() {
        Map<CommandType, Class<? extends Command>> mapping = new HashMap<>();
        mapping.put(MY_COMMAND, MyCommand.class);
        return mapping;
    }
}
class MyCommandTypeMappingFactory : CommandTypeMappingFactory {

    override fun create(): Map<CommandType, Class<out Command>> {
        val mapping = mutableMapOf<CommandType, Class<out Command>>()
        mapping[MY_COMMAND] = MyCommand::class.java
        return mapping.toMap()
    }

    companion object {
        val MY_COMMAND = CommandType(0)
    }
}

Then pass it to the ConnectivityApiBuilder:

_

ConnectivityApi connectivityApi = new PriorityConnectivityApiBuilder(context)
            .addCommunicator(communicatorFactory)
            .addModule(new CommonCommandModule())
            .addMapping(new MyCommandTypeMappingFactory())
            .withStatusHandler(statusHandler)
            .build()
val connectivityApi = PriorityConnectivityApiBuilder(context)
            .addCommunicator(communicatorFactory)
            .addModule(CommonCommandModule())
            .addMapping(MyCommandTypeMappingFactory())
            .withStatusHandler(statusHandler)
            .build()

Module

Alternatively you can implement CommandModule interface which will provide complete set of extensions.

_

public class MyCommandModule implements CommandModule {
    @Override
    public CommandSerializersFactory createSerializerFactory() {
        return new MyCommandSerializersFactory();
    }

    @Override
    public CommandDeserializerFactory createDeserializersFactory() {
        return new MyCommandDeserializersFactory();
    }

    @Override
    public CommandTypeMappingFactory createMappingFactory() {
        return new MyCommandTypeMappingFactory();
    }
}
class MyCommandModule : CommandModule {

    override fun createDeserializersFactory(): CommandDeserializersFactory {
        return MyCommandDeserializersFactory()
    }

    override fun createMappingFactory(): CommandTypeMappingFactory {
        return MyCommandTypeMappingFactory()
    }

    override fun createSerializerFactory(): CommandSerializersFactory {
        return MyCommandSerializersFactory()
    }
}

Bluetooth SPP

Bluetooth SPP initialization

Maps SDK for Android provides users with ability to share data through Bluetooth using Serial Port Profile(SPP).

To obtain access to this module you will need to add proper dependency to your build.gradle file:

implementation("com.tomtom.online:sdk-connectivity-bluetooth:2.4292")

To use Bluetooth module you will need to create an instances of Communicator on both client and server side, which is used to manage connections.
Achieve that by using factories BtSppClientFactory and BtSppServerFactory.

Each of builders requires:

  • ConnectionParams

Specify communication parameters of a device in the following manner:

  • Server side:

            BtSppConnectionParams.createServer(
                secure = true,
                uuid = UUID.fromString(SERVER_UUID),
                name = serviceName
            )
  • Client side:

                BtSppConnectionParams.createClient(
                        secure = true,
                        uuid = UUID.fromString(CLIENT_UUID),
                        mac = macAddress
                )

Bluetooth Low Energy

Bluetooth Low Energy initialization

Maps SDK for Android provides users with ability to share data through Bluetooth Low Energy.

To obtain access to this module you will need to add proper dependency to your build.gradle file:

Client:

implementation("com.tomtom.online:sdk-connectivity-bluetooth-le:2.4292")

 

Server:

implementation("com.tomtom.online:sdk-connectivity-server-bt-le:2.4292")

 

To use Bluetooth Low Energy module you will need to create an Communicator on both client and server side, which is used to manage connections.
Achieve that by using factories BleClientFactory and BleServerFactory.

Each of factories requires ConnectionParams.

Specify communication parameters of a device in the following manner:

  • Server side:

        return BleServerConnectionParams.Builder().build()
  • Client side:

        return BleClientConnectionParams(macAddress)

Api Reference

API Reference for Connectivity



Older versions Changes between current version

Connectivity_2.4.287

N/A

Connectivity_2.4.283

N/A

Connectivity_2.4.264

N/A

Connectivity_2.4.260

N/A

You are here