A simple MQTT Service that will keep running for the duration of your Android application using the Paho Java MQTT Client.

Overview

DEPRECATED

I would strongly recommend using the official Paho Android client.

Setup

  • Make sure to add the service to your AndroidManifest.xml
  • Edit the appropriate fields in the class with the information required

Simple Example

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
         android:versionCode="1"
         android:versionName="1.0">

         <receiver android:name=".MyReceiver" android:enabled="true" android:exported="false">
             <intent-filter>
                 <action android:name="android.intent.action.BOOT_COMPLETED" />
             </intent-filter>
         </receiver>

         <service android:name="com.jessefarebro.mqtt.MqttService" android:exported="false" />

         <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
</manifest>

License

Copyright 2013 Jesse Farebrother

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Comments
  • Starting Service

    Starting Service

    Hi, sorry i am new in android programming. Can you describe more detail how to use this service?

    I had tried made a new project in Android Studio,

    then I have added the MqttService.java to my java/..../ folder,

    add " " to AndroidManifest.xml

    and according this http://www.techotopia.com/index.php/Implementing_an_Android_Started_Service_in_Android_Studio, i started MqttService's Service with this command Intent intent = new Intent(this, MqttService.class); startService(intent); in my mainactivity

    but it seems from my MQTT broker, that program doesn't connect to MQTT broker.

    How to use this code correctly?

    Thank you :)

    opened by muhammadsatrio 3
  • Need More Details

    Need More Details

    Hi Jesse, How can i handle the response messages from receiver(i am a sender)..messageArrived method will have all the responses (or) it will have only themessage which has been sent by user atlast . . .if u have any flow diagram for mqtt working actions for android pls provide .. ..

    opened by praveenkumar66 3
  • topic to keep alive

    topic to keep alive

    Sir. I donot think it a good idea to kepp alive by publishing a topic. As I have tested your code, to publish a topic needs sending at lease 7 or 8 bytes. while the mqtt heartbeat is only 2 bytes. That means the best advantage of mqtt is not longer existed.
    We could send the MqttPingReq by modify the paho code. See : https://github.com/chinesejie/paho-for-android

    opened by chinesejie 3
  • MqttConnectOptions not used when connecting

    MqttConnectOptions not used when connecting

    Hey,

    thanks for this great example.

    I think i found a bug in your service. You create an MqttConnectOptions object (mOpts) and set a clean session (https://github.com/JesseFarebro/Android-Paho-MQTT-Service/blob/master/src/com/jessefarebro/mqtt/MqttService.java#L134-135). However, mOpts is not used when connecting ( https://github.com/JesseFarebro/Android-Paho-MQTT-Service/blob/master/src/com/jessefarebro/mqtt/MqttService.java#L247).

    Needs to be changed to "mClient.connect(mOpts);". Found it when I tried to set username and password :)

    Thanks, Sebastian

    bug 
    opened by sebaroesch 1
  • ActiveMq+android-mqtt

    ActiveMq+android-mqtt

    when I close wife and reconnected at de.eclipsemagazin.mqtt.push.MqttService.sendKeepAlive(MqttService.java:426) at de.eclipsemagazin.mqtt.push.MqttService.keepAlive(MqttService.java:328) at de.eclipsemagazin.mqtt.push.MqttService.onStartCommand(MqttService.java:171) Would you mind answering this quesstions?

    opened by Eminem8080 3
Owner
Jesse Farebrother
Graduate student @mila-iqia. Previously CS @ualberta / @AmiiThinks.
Jesse Farebrother
MQTT, publisher-subscriber, Applicazione android per il monitoraggio dello stato vitale dell'utente e dell'ambiente circostante.

MQTT, publisher-subscriber, Applicazione android per il monitoraggio dello stato vitale dell'utente e dell'ambiente circostante.

Andrea Castronovo 2 Jan 12, 2022
A Kotlin client for the gRPC based Bar Service

Bar Service Kotlin Client Overview This directory contains a simple bar service client written in Kotlin against generated models (protos) You can fin

Hypto 1 Nov 18, 2021
Kotlin-echo-client - Echo client using Kotlin with Ktor networking library

Overview This repository contains an echo server implemented with Kotlin and kto

Elliot Barlas 2 Sep 1, 2022
Simple kafka client for monitoring topic events. Client has UI powered by Darklaf

kafka-client Simple kafka client for monitoring topic values. How to start $ java -jar kafka-client-1.0.jar How to use specify kafka hosts in config.y

Salavat 0 Jun 3, 2022
LiteHttp is a simple, intelligent and flexible HTTP framework for Android. With LiteHttp you can make HTTP request with only one line of code! It could convert a java model to the parameter and rander the response JSON as a java model intelligently.

Android network framework: LiteHttp Tags : litehttp2.x-tutorials Website : http://litesuits.com QQgroup : 42960650 , 47357508 Android网络通信为啥子选 lite-htt

马天宇 829 Dec 29, 2022
This application provide purchase request service for Membership Console.

Purchase Request 概要 本プロジェクトはMembership Consoleの購入申請機能を提供します。 開発 開発環境 Java OpenJDK 17 Kotlin 1.7.10 Ktor 2.1.2 PostgreSQL 13 docker-compose ビルド方法 ビルドに成

Membership Console 2 Nov 17, 2022
A product registration service using the Kotlin language and the Micronaut and Grpc framework

A product registration service using the Kotlin language and the Micronaut and Grpc framework

Mateus Araújo 30 Nov 2, 2022
Ktor-Client this is the client part that uses the Ktor server

Ktor-Client this is the client part that uses the Ktor server Previews Tech stack & Open source libraries Minimum SDK level 21. Kotlin+ Coroutines + F

Mohamed Emad 4 Dec 23, 2022
Asynchronous Http and WebSocket Client library for Java

Async Http Client Follow @AsyncHttpClient on Twitter. The AsyncHttpClient (AHC) library allows Java applications to easily execute HTTP requests and a

AsyncHttpClient 6k Jan 8, 2023
Unirest in Java: Simplified, lightweight HTTP client library.

Unirest for Java Install With Maven: <!-- Pull in as a traditional dependency --> <dependency> <groupId>com.konghq</groupId> <artifactId>unire

Kong 2.4k Jan 5, 2023
Unirest in Java: Simplified, lightweight HTTP client library.

Unirest for Java Install With Maven: <!-- Pull in as a traditional dependency --> <dependency> <groupId>com.konghq</groupId> <artifactId>unire

Kong 2.4k Dec 24, 2022
Kotlin-REST-Retrofit - Simple client to consume a REST API with Retrofit using Kotlin

Kotlin REST Retrofit Sencillo cliente para consumir una API REST con Retrofit us

José Luis González Sánchez 5 Nov 4, 2022
A service storing files in the cloud, providing a link for downloading.

Zippy The Werewolf About A service storing files in the cloud, providing a link for downloading. The basic idea Zippy The Werewolf will accept any fil

null 1 Mar 17, 2022
Android network client based on Cronet. This library let you easily use QUIC protocol in your Android projects

Android network client based on Cronet. This library let you easily use QUIC protocol in your Android projects

VK.com 104 Dec 12, 2022
Ktorfit - a HTTP client/Kotlin Symbol Processor for Kotlin Multiplatform (Js, Jvm, Android, iOS, Linux) using KSP and Ktor clients inspired by Retrofit

Ktorfit is a HTTP client/Kotlin Symbol Processor for Kotlin Multiplatform (Js, Jvm, Android, iOS, Linux) using KSP and Ktor clients inspired by Retrofit

Jens Klingenberg 637 Dec 25, 2022
Monitoring water tanker level using NodeMCU ESP8266 and HC-SR04P Ultrasonic Sensor and broadcasting it using a simple HTTP server inside NodeMCU ESP8266 and show data in an Android App

WaterLevel Preface This project aims to finding a tanker water level using NodeMCU with ESP8266 core and HC-SR04P Ultrasonic sensor and broadcasting i

YaMiN 12 Dec 20, 2022
Square’s meticulous HTTP client for the JVM, Android, and GraalVM.

OkHttp See the project website for documentation and APIs. HTTP is the way modern applications network. It’s how we exchange data & media. Doing HTTP

Square 43.4k Jan 5, 2023
A type-safe HTTP client for Android and the JVM

Retrofit A type-safe HTTP client for Android and Java. For more information please see the website. Download Download the latest JAR or grab from Mave

Square 41k Jan 5, 2023