The MQTT Connection Library provides a simple connection UI as well as logic to perform an MQTT connection in an Android app. If additional options are needed for the connection (beyond the provided), there is a capability that can be utilized. Please read Development Instructions for more detail.
It is important to note that the pieces provided in the library cannot stand on their own. Most classes are to be extended or implemented, as an "MQTT Connection" relies on a service that drives the logic using the connection. We will go over the correct way to wire everything together below.
- Ensure that the correct version of the library is included in the consuming project's
build.gradle
file, under its dependencies:
implementation 'com.craxiom:mqttlibrary:0.7.4'
- Next, for the connection UI, the
fragment_mqtt_connection
is readily available underres/layout
; however,AConnectionFragment
must still be extended, orDefaultConnectionFragment
.
Note: Users can extend the latter if they do not wish to add extra UI components. Otherwise, extendAConnectionFragment
, which contains methods marked with "additional" in their names and must be overridden in the child class.
a. Whichever fragment ends up being extended, it will require a binder parameter. This binder should extend the providedAConnectionFragment#ServiceBinder
in order to be recognized. Likely, this binder will be located in theIMqttService
implementation of the consuming project. - Moving on to the service interface,
IMqttService
: The fragment relies on the service to perform the connection backend logic. For example, if the user toggles the connection switch, the fragment will callIMqttService#connectToMqttBroker
. - The
IMqttService
implementation should ideally include aDefaultMqttConnection
, which will perform connection/disconnection. - Additionally, the
BrokerConnectionInfo
holds relevant information in order to successfully make an MQTT connection. It is important to note that one should extend this class if additional fields are needed and these fields should correspond to the additional fragment UI components, if any.
- Execute
gradlew build
in the root directory to produce the Android AAR library. - Execute
gradlew publishDebugPublicationToMavenLocal
in the root directory to publish the debug aar artifact to the local Maven cache. - Execute
gradlew publishReleasePublicationToMavenLocal
in the root directory to publish the release aar artifact to the local Maven cache.
See the change log for details about each release: CHANGELOG.md
- Eliza Alcaraz - eliza-mae-alcaraz
- Christian Rowlands - Craxiom