Coder Social home page Coder Social logo

paho.mqtt.android's Introduction

MQTT Android Service

The MQTT Android Service is an MQTT client library written in Kotlin. It has been created to provide reliable open-source implementations of open and standard messaging protocols aimed at new, existing, and emerging applications for Machine-to-Machine (M2M) and Internet of Things (IoT). MQTT reflects the inherent physical and cost constraints of device connectivity. Its objectives include effective levels of decoupling between devices and applications, designed to keep markets open and encourage the rapid growth of scalable Web and Enterprise middleware and applications.

Features

MQTT 3.1 ✔️ Automatic Reconnect ✔️
MQTT 3.1.1 ✔️ Offline Buffering ✔️
LWT ✔️ WebSocket Support ✔️
SSL / TLS ✔️ Standard TCP Support ✔️
Message Persistence ✔️

Using this MQTT Android Client

Jitpack.io

More details are here https://jitpack.io/#hannesa2/paho.mqtt.android

  allprojects {
    repositories {
      ...
      maven { url 'https://jitpack.io' }
    }
  }
dependencies {
  implementation 'androidx.legacy:legacy-support-v4:1.0.0'
  implementation 'com.github.hannesa2:paho.mqtt.android:$latestVersion'
}

Background behavior

Version 4.x doesn't need a foreground service

The main advantages

  • it doesn't use android.permission.SCHEDULE_EXACT_ALARM which drain the battery
  • it uses androidx.work:work-runtime-ktx to receive messages during device sleep

Version 3.x and Android O foreground service (deprecated)

When you use a version 3.x on Android >= O you should use it as foreground service

val client = MqttAndroidClient(context, uri, clientId).apply {
    setForegroundService(foregroundNotification, 3)
}

License

Copyright 2024

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.

paho.mqtt.android's People

Contributors

alabrecq avatar anaktas avatar blundell avatar chihung93 avatar dependabot[bot] avatar dudukee avatar erguotou avatar fabmazz avatar fjeagle avatar gradle-update-robot avatar hannesa2 avatar hoangchungk53qx1 avatar icraggs avatar idiazt avatar jorisbodin avatar jpwsutton avatar kumahyung avatar linster avatar mcarrer avatar mgasztold avatar miketran78727 avatar nisrulz avatar paulo-raca avatar peterjeschke avatar powturns avatar protectedman avatar raontie avatar tynox avatar vuptt avatar zyyangbj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

paho.mqtt.android's Issues

why return false? backgroundExecute the response

CoroutineScope(Dispatchers.IO).launch {
                measureTimeMillis {
                    @Suppress("BlockingMethodInNonBlockingContext")
                    val response = CoroutineScope(Dispatchers.IO).async {
                        return@async backgroundExecute(clientComms)
                    }.await()
                    Timber.d("Request done $response")

                    if (wakelock.isHeld) {
                        wakelock.release()
                    }
                }.also {
                    Timber.d("Completed in $it ms")
                }
            }

$AlarmReceiver$onReceive.invokeSuspend(): Request done false

Manifest merger failed

I'm trying to use this library instead as it supports Android 12 but I can't get my application to compile after using it, I tried to import the library using different methods but they all produce the same error:

`
myproject\app\src\main\AndroidManifest.xml:23:13-60 Error:
Attribute provider#androidx.core.content.FileProvider@authorities value=(myproject.provider) from [com.github.AppDevNext.Logcat:LogcatCoreLib:2.9.5] AndroidManifest.xml:23:13-60
is also present at [com.mindorks:paracamera:0.2.2] AndroidManifest.xml:18:13-65 value=(myproject.imageprovider).
Suggestion: add 'tools:replace="android:authorities"' to element at AndroidManifest.xml:21:9-29:20 to override.
myproject\app\src\main\AndroidManifest.xml:28:17-55 Error:
Attribute meta-data#android.support.FILE_PROVIDER_PATHS@resource value=(@xml/provider_paths) from [com.github.AppDevNext.Logcat:LogcatCoreLib:2.9.5] AndroidManifest.xml:28:17-55
is also present at [com.mindorks:paracamera:0.2.2] AndroidManifest.xml:23:17-51 value=(@xml/file_paths).
Suggestion: add 'tools:replace="android:resource"' to element at AndroidManifest.xml to override.

See http://g.co/androidstudio/manifest-merger for more information about the manifest merger.

Execution failed for task ':app:processDebugMainManifest'.

Manifest merger failed with multiple errors, see logs

  • Try:
    Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Exception is:
    org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:processDebugMainManifest'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecuter.java:200)
    at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:263)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeIfValid(ExecuteActionsTaskExecuter.java:198)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:179)
    at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:109)
    at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:46)
    at org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter.execute(ResolveTaskExecutionModeExecuter.java:62)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:57)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:56)
    at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:36)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:77)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:55)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:52)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:200)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:195)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$3.execute(DefaultBuildOperationRunner.java:75)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$3.execute(DefaultBuildOperationRunner.java:68)
    at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:153)
    at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:68)
    at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:62)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.lambda$call$2(DefaultBuildOperationExecutor.java:76)
    at org.gradle.internal.operations.UnmanagedBuildOperationWrapper.callWithUnmanagedSupport(UnmanagedBuildOperationWrapper.java:54)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:76)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:52)
    at org.gradle.execution.plan.LocalTaskNodeExecutor.execute(LocalTaskNodeExecutor.java:41)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:372)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:359)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:352)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:338)
    at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.lambda$run$0(DefaultPlanExecutor.java:127)
    at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.execute(DefaultPlanExecutor.java:191)
    at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.executeNextNode(DefaultPlanExecutor.java:182)
    at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:124)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
    Caused by: java.lang.RuntimeException: Manifest merger failed with multiple errors, see logs
    at com.android.build.gradle.internal.tasks.manifest.ManifestHelperKt.mergeManifests(ManifestHelper.kt:87)
    at com.android.build.gradle.tasks.ProcessApplicationManifest.doFullTaskAction(ProcessApplicationManifest.kt:144)
    at com.android.build.gradle.internal.tasks.IncrementalTask.handleIncrementalInputs(IncrementalTask.kt:110)
    at com.android.build.gradle.internal.tasks.IncrementalTask.access$handleIncrementalInputs(IncrementalTask.kt:65)
    at com.android.build.gradle.internal.tasks.IncrementalTask$taskAction$$inlined$recordTaskAction$1.invoke(BaseTask.kt:62)
    at com.android.build.gradle.internal.tasks.Blocks.recordSpan(Blocks.java:51)
    at com.android.build.gradle.internal.tasks.IncrementalTask.taskAction$gradle_core(IncrementalTask.kt:137)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:104)
    at org.gradle.api.internal.project.taskfactory.IncrementalTaskInputsTaskAction.doExecute(IncrementalTaskInputsTaskAction.java:47)
    at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:51)
    at org.gradle.api.internal.project.taskfactory.AbstractIncrementalTaskAction.execute(AbstractIncrementalTaskAction.java:25)
    at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:29)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$3.run(ExecuteActionsTaskExecuter.java:555)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:29)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:26)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$3.execute(DefaultBuildOperationRunner.java:75)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$3.execute(DefaultBuildOperationRunner.java:68)
    at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:153)
    at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:68)
    at org.gradle.internal.operations.DefaultBuildOperationRunner.run(DefaultBuildOperationRunner.java:56)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.lambda$run$1(DefaultBuildOperationExecutor.java:71)
    at org.gradle.internal.operations.UnmanagedBuildOperationWrapper.runWithUnmanagedSupport(UnmanagedBuildOperationWrapper.java:45)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:71)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:540)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:523)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.access$300(ExecuteActionsTaskExecuter.java:108)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$TaskExecution.executeWithPreviousOutputFiles(ExecuteActionsTaskExecuter.java:271)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$TaskExecution.execute(ExecuteActionsTaskExecuter.java:260)
    at org.gradle.internal.execution.steps.ExecuteStep.lambda$execute$0(ExecuteStep.java:33)
    at org.gradle.internal.execution.steps.ExecuteStep.execute(ExecuteStep.java:33)
    at org.gradle.internal.execution.steps.ExecuteStep.execute(ExecuteStep.java:26)
    at org.gradle.internal.execution.steps.CleanupOutputsStep.execute(CleanupOutputsStep.java:67)
    at org.gradle.internal.execution.steps.CleanupOutputsStep.execute(CleanupOutputsStep.java:36)
    at org.gradle.internal.execution.steps.ResolveInputChangesStep.execute(ResolveInputChangesStep.java:49)
    at org.gradle.internal.execution.steps.ResolveInputChangesStep.execute(ResolveInputChangesStep.java:34)
    at org.gradle.internal.execution.steps.CancelExecutionStep.execute(CancelExecutionStep.java:43)
    at org.gradle.internal.execution.steps.TimeoutStep.executeWithoutTimeout(TimeoutStep.java:73)
    at org.gradle.internal.execution.steps.TimeoutStep.execute(TimeoutStep.java:54)
    at org.gradle.internal.execution.steps.CreateOutputsStep.execute(CreateOutputsStep.java:44)
    at org.gradle.internal.execution.steps.SnapshotOutputsStep.execute(SnapshotOutputsStep.java:54)
    at org.gradle.internal.execution.steps.SnapshotOutputsStep.execute(SnapshotOutputsStep.java:38)
    at org.gradle.internal.execution.steps.BroadcastChangingOutputsStep.execute(BroadcastChangingOutputsStep.java:42)
    at org.gradle.internal.execution.steps.CacheStep.executeWithoutCache(CacheStep.java:159)
    at org.gradle.internal.execution.steps.CacheStep.execute(CacheStep.java:72)
    at org.gradle.internal.execution.steps.CacheStep.execute(CacheStep.java:43)
    at org.gradle.internal.execution.steps.StoreExecutionStateStep.execute(StoreExecutionStateStep.java:44)
    at org.gradle.internal.execution.steps.StoreExecutionStateStep.execute(StoreExecutionStateStep.java:33)
    at org.gradle.internal.execution.steps.RecordOutputsStep.execute(RecordOutputsStep.java:38)
    at org.gradle.internal.execution.steps.RecordOutputsStep.execute(RecordOutputsStep.java:24)
    at org.gradle.internal.execution.steps.SkipUpToDateStep.executeBecause(SkipUpToDateStep.java:92)
    at org.gradle.internal.execution.steps.SkipUpToDateStep.lambda$execute$0(SkipUpToDateStep.java:85)
    at org.gradle.internal.execution.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:55)
    at org.gradle.internal.execution.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:39)
    at org.gradle.internal.execution.steps.ResolveChangesStep.execute(ResolveChangesStep.java:76)
    at org.gradle.internal.execution.steps.ResolveChangesStep.execute(ResolveChangesStep.java:37)
    at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsFinishedStep.execute(MarkSnapshottingInputsFinishedStep.java:36)
    at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsFinishedStep.execute(MarkSnapshottingInputsFinishedStep.java:26)
    at org.gradle.internal.execution.steps.ResolveCachingStateStep.execute(ResolveCachingStateStep.java:94)
    at org.gradle.internal.execution.steps.ResolveCachingStateStep.execute(ResolveCachingStateStep.java:49)
    at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.execute(CaptureStateBeforeExecutionStep.java:79)
    at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.execute(CaptureStateBeforeExecutionStep.java:53)
    at org.gradle.internal.execution.steps.ValidateStep.execute(ValidateStep.java:74)
    at org.gradle.internal.execution.steps.SkipEmptyWorkStep.lambda$execute$2(SkipEmptyWorkStep.java:78)
    at org.gradle.internal.execution.steps.SkipEmptyWorkStep.execute(SkipEmptyWorkStep.java:78)
    at org.gradle.internal.execution.steps.SkipEmptyWorkStep.execute(SkipEmptyWorkStep.java:34)
    at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsStartedStep.execute(MarkSnapshottingInputsStartedStep.java:39)
    at org.gradle.internal.execution.steps.LoadExecutionStateStep.execute(LoadExecutionStateStep.java:40)
    at org.gradle.internal.execution.steps.LoadExecutionStateStep.execute(LoadExecutionStateStep.java:28)
    at org.gradle.internal.execution.impl.DefaultWorkExecutor.execute(DefaultWorkExecutor.java:33)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeIfValid(ExecuteActionsTaskExecuter.java:187)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:179)
    at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:109)
    at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:46)
    at org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter.execute(ResolveTaskExecutionModeExecuter.java:62)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:57)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:56)
    at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:36)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:77)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:55)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:52)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:200)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:195)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$3.execute(DefaultBuildOperationRunner.java:75)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$3.execute(DefaultBuildOperationRunner.java:68)
    at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:153)
    at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:68)
    at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:62)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.lambda$call$2(DefaultBuildOperationExecutor.java:76)
    at org.gradle.internal.operations.UnmanagedBuildOperationWrapper.callWithUnmanagedSupport(UnmanagedBuildOperationWrapper.java:54)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:76)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:52)
    at org.gradle.execution.plan.LocalTaskNodeExecutor.execute(LocalTaskNodeExecutor.java:41)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:372)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:359)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:352)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:338)
    at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.lambda$run$0(DefaultPlanExecutor.java:127)
    at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.execute(DefaultPlanExecutor.java:191)
    at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.executeNextNode(DefaultPlanExecutor.java:182)
    at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:124)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)`

After checking the AndroidManifest merger, I only found one warning:
Merging Errors: Warning application@android:networkSecurityConfig was tagged at AndroidManifest.xml:72 to replace other declarations but no other declaration present connected.app main manifest (this file), line 71

Notification is not removing when we set setForegroundService in mqtt client

We have added the notification in mqtt for show the notification in notification bar but when we logout the app the notification bar still showing.
We have used below mentioned code.
mqttClient!!.setForegroundService(notification.build(), notificationId)

And also used code for cancel notification
val notificationManager = context getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager notificationManager.cancel(notificationId)

Can you please provide the solution for stop the foreground service.

Cannot perform this operation because the connection pool has been closed.

Thread Name: 'main'
Back traces starts.
java.lang.IllegalStateException: Cannot perform this operation because the connection pool has been closed.
at android.database.sqlite.SQLiteConnectionPool.throwIfClosedLocked(SQLiteConnectionPool.java:1069)
at android.database.sqlite.SQLiteConnectionPool.waitForConnection(SQLiteConnectionPool.java:683)
at android.database.sqlite.SQLiteConnectionPool.acquireConnection(SQLiteConnectionPool.java:378)
at android.database.sqlite.SQLiteSession.acquireConnection(SQLiteSession.java:894)
at android.database.sqlite.SQLiteSession.executeForChangedRowCount(SQLiteSession.java:752)
at android.database.sqlite.SQLiteStatement.executeUpdateDelete(SQLiteStatement.java:64)
at androidx.sqlite.db.framework.FrameworkSQLiteStatement.executeUpdateDelete(FrameworkSQLiteStatement.java:46)
at info.mqtt.android.service.room.c.b(MqMessageDao_Impl.java:229)
at info.mqtt.android.service.d.j(MqttConnection.kt:105)
at info.mqtt.android.service.MqttService.j(MqttService.kt:289)
at info.mqtt.android.service.MqttAndroidClient.K(MqttAndroidClient.kt:253)
at info.mqtt.android.service.MqttAndroidClient.a(MqttAndroidClient.kt:39)
at info.mqtt.android.service.MqttAndroidClient$b.onServiceConnected(MqttAndroidClient.kt:1259)
at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1771)
at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1803)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:7085)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:511)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:928)
Back traces ends.

Version used is implementation 'com.github.hannesa2:paho.mqtt.android:3.3.5-beta2' or 3.4.0
Report this error often and then back off
Excuse me, how should solve. thank you

Access to sessionPresent after automatic reconnect

Thanks for this fork and the maintenance.

I am testing a persistent connection between app and broker:
I am using the sessionPresent flag after a successul connection to decide if a new subscription is necessary: If server acknowlegdes the connection and set the sessionPresent=true, the app wont need new subscriptions.

But I can't access the sessionPresent flag after a automatic reconnect, because the onSuccess-callback of my IMqttActionListeneris not called. Only the IMqttActionListener onSuccess-callback contains the token for that flag

Am I wrong with my concept of connection and subscription - or might it be useful to implement some sort of access to that sessionPresent flag during the reconnection?

android.database.CursorWindowAllocationException

05-01 08:22:27.868 4394 6705 E CursorWindow: Could not allocate CursorWindow '/data/user/0/com.xxx.xxxx/databases/messageMQ' of size 2097152 due to error -12.
9705-01 08:22:27.868 4394 6705 E CrashHandler: In thread: Thread[arch_disk_io_4,5,main]
9805-01 08:22:27.868 4394 6705 E CrashHandler: UncaughtException detected: android.database.CursorWindowAllocationException: Cursor window allocation of 2048 kb failed. # Open Cursors=1 (# cursors opened by this proc=1)
9905-01 08:22:27.868 4394 6705 E CrashHandler: at android.database.CursorWindow.(CursorWindow.java:108)
10005-01 08:22:27.868 4394 6705 E CrashHandler: at android.database.AbstractWindowedCursor.clearOrCreateWindow(AbstractWindowedCursor.java:198)
10105-01 08:22:27.868 4394 6705 E CrashHandler: at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:138)
10205-01 08:22:27.868 4394 6705 E CrashHandler: at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:132)
10305-01 08:22:27.868 4394 6705 E CrashHandler: at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:219)
10405-01 08:22:27.868 4394 6705 E CrashHandler: at android.database.AbstractCursor.moveToNext(AbstractCursor.java:268)
10505-01 08:22:27.868 4394 6705 E CrashHandler: at androidx.room.InvalidationTracker$1.checkUpdatedTable(InvalidationTracker.java:463)
10605-01 08:22:27.868 4394 6705 E CrashHandler: at androidx.room.InvalidationTracker$1.run(InvalidationTracker.java:433)
10705-01 08:22:27.868 4394 6705 E CrashHandler: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
10805-01 08:22:27.868 4394 6705 E CrashHandler: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
10905-01 08:22:27.868 4394 6705 E CrashHandler: at java.lang.Thread.run(Thread.java:818)

Build error when rebuilding this project

Hi,
I get an error when I try to build this project.

What is the correct way to build this project?
I'm using Android Studio 4.1.3.

FAILURE: Build failed with an exception.

* Where:
Build file 'D:\WS\paho.mqtt.android (hannresa2)\extendedSample\build.gradle' line: 3

* What went wrong:
A problem occurred evaluating project ':extendedSample'.
> Failed to apply plugin 'com.github.dcendents.android-maven'.
   > Could not create plugin of type 'AndroidMavenPlugin'.
      > Could not generate a decorated class for type AndroidMavenPlugin.
         > org/gradle/api/publication/maven/internal/MavenPomMetaInfoProvider

PS: I'm evaluating this library, I'm currently using the original "paho.mqtt.android" but I have a lot of performance problems.

Crashes still happening on v3.3.2

Fatal Exception: java.lang.Throwable: not connected
       at info.mqtt.android.service.MqttAndroidClient.simpleAction(MqttAndroidClient.kt:997)
       at info.mqtt.android.service.MqttAndroidClient.sendAction(MqttAndroidClient.kt:1019)
       at info.mqtt.android.service.MqttAndroidClient.onReceive(MqttAndroidClient.kt:893)
       at androidx.localbroadcastmanager.content.LocalBroadcastManager.executePendingBroadcasts(LocalBroadcastManager.java:313)
       at androidx.localbroadcastmanager.content.LocalBroadcastManager$1.handleMessage(LocalBroadcastManager.java:121)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loop(Looper.java:263)
       at android.app.ActivityThread.main(ActivityThread.java:8283)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:612)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1006)

Please help me. Why is this happening?

why is android O devices needs to be set as foreground service?

Hello

I want to use this lib instead this one:
https://github.com/eclipse/paho.mqtt.android
because I had the Targeting S+ (version 10000 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent. error.

In here I saw that it is needed to add this line for android O devices:

val client = MqttAndroidClient(context, uri, clientId).apply {
    setForegroundService(foregroundNotification, 3)
}
  1. why is this needed? what is the foregraound service means and do I need to do any other refactroing to my code except for this?
  2. what is the foregroundNotification variable? I don't use anything like it curently

thanks!

3.6.0-beta1

E/SQLiteDatabase: Failed to open database '/data/user/0/com.demo/no_backup/androidx.work.workdb'.
android.database.sqlite.SQLiteException: Failed to change locale for db '/data/user/0/com.demo/no_backup/androidx.work.workdb' to 'zh_CN'.
at android.database.sqlite.SQLiteConnection.setLocaleFromConfiguration(SQLiteConnection.java:394)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:219)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:194)
at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:493)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:200)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:192)
at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:864)
at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:849)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:724)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:714)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:295)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:238)
at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableSupportDatabase(FrameworkSQLiteOpenHelper.java:151)
at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase(FrameworkSQLiteOpenHelper.java:112)
at androidx.room.RoomDatabase.inTransaction(RoomDatabase.java:706)
at androidx.room.RoomDatabase.assertNotSuspendingTransaction(RoomDatabase.java:483)
at androidx.work.impl.model.SystemIdInfoDao_Impl.getWorkSpecIds(SystemIdInfoDao_Impl.java:120)
at androidx.work.impl.background.systemjob.SystemJobScheduler.reconcileJobs(SystemJobScheduler.java:298)
at androidx.work.impl.utils.ForceStopRunnable.cleanUp(ForceStopRunnable.java:249)
at androidx.work.impl.utils.ForceStopRunnable.forceStopRunnable(ForceStopRunnable.java:215)
at androidx.work.impl.utils.ForceStopRunnable.run(ForceStopRunnable.java:110)
at androidx.work.impl.utils.SerialExecutor$Task.run(SerialExecutor.java:91)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
Caused by: android.database.sqlite.SQLiteDatabaseCorruptException: database disk image is malformed (code 11)
at android.database.sqlite.SQLiteConnection.nativeExecuteForString(Native Method)
at android.database.sqlite.SQLiteConnection.executeForString(SQLiteConnection.java:642)
at android.database.sqlite.SQLiteConnection.setLocaleFromConfiguration(SQLiteConnection.java:375)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:219) 
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:194) 
at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:493) 
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:200) 
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:192) 
at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:864) 
at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:849) 
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:724) 
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:714) 
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:295) 
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:238) 
at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableSupportDatabase(FrameworkSQLiteOpenHelper.java:151) 
at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase(FrameworkSQLiteOpenHelper.java:112) 
at androidx.room.RoomDatabase.inTransaction(RoomDatabase.java:706) 
at androidx.room.RoomDatabase.assertNotSuspendingTransaction(RoomDatabase.java:483) 
at androidx.work.impl.model.SystemIdInfoDao_Impl.getWorkSpecIds(SystemIdInfoDao_Impl.java:120) 
at androidx.work.impl.background.systemjob.SystemJobScheduler.reconcileJobs(SystemJobScheduler.java:298) 
at androidx.work.impl.utils.ForceStopRunnable.cleanUp(ForceStopRunnable.java:249) 
at androidx.work.impl.utils.ForceStopRunnable.forceStopRunnable(ForceStopRunnable.java:215) 
at androidx.work.impl.utils.ForceStopRunnable.run(ForceStopRunnable.java:110) 
at androidx.work.impl.utils.SerialExecutor$Task.run(SerialExecutor.java:91) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) 
at java.lang.Thread.run(Thread.java:764) 

basicSample losing connection

Hi,
I tried the basicSample application in hope it would not lose the connection to the mqtt broker as my app using the original service did. Unfortunately, I am losing the connection as well.

The changes I made to the sample:

I tried the app in the emulator and it works fine. On the phone (Motorola with Android 11) after the screen goes black, ca 90 seconds later, it loses the connection:

16:43.58.067 Reconnected to ...
16:43.58.161 Subscribed!
16:47.34.013 The Connection was lost.
16:47.41.306 Reconnected to ... etc,etc

It does not matter if I'm connected to Wifi or Mobile data.

Is there anything I can do to fix it?
Thanks.

Edit: the 90 seconds I mentioned may be misleading, I currently observed virtually any time between reconnecting and losing the connection.

System App Error

Sending non-protected broadcast MqttService.pingSender.*** from system uid 1000 pkg ***
java.lang.Throwable
at com.android.server.am.ActivityManagerService.checkBroadcastFromSystem(ActivityManagerService.java:16116)
at com.android.server.am.ActivityManagerService.broadcastIntentLocked(ActivityManagerService.java:16787)
at com.android.server.am.ActivityManagerService.broadcastIntentInPackage(ActivityManagerService.java:16989)
at com.android.server.am.ActivityManagerService$LocalService.broadcastIntentInPackage(ActivityManagerService.java:19650)
at com.android.server.am.PendingIntentRecord.sendInner(PendingIntentRecord.java:442)
at com.android.server.am.PendingIntentRecord.sendWithResult(PendingIntentRecord.java:285)
at com.android.server.am.ActivityManagerService.sendIntentSender(ActivityManagerService.java:5837)
at android.app.PendingIntent.sendAndReturnResult(PendingIntent.java:913)
at android.app.PendingIntent.send(PendingIntent.java:884)
at com.android.server.AlarmManagerService$DeliveryTracker.deliverLocked(AlarmManagerService.java:4796)
at com.android.server.AlarmManagerService.deliverAlarmsLocked(AlarmManagerService.java:3926)
at com.android.server.AlarmManagerService$AlarmThread.run(AlarmManagerService.java:4175)

Could you don't use AlarmManager?

Notification is not removing.

I have attached a notification when starting the service like below

mqttClient!!.setForegroundService(notification.build(), notificationId)

Now my issue is when I disconnect and close the mqtt connection still notification not removed from the status bar. Please suggest how can I remove that notification after mqtt disconnection.

I have used

val notificationManager = NotificationManagerCompat.from(context)
notificationManager.cancel(notificationId)

and

val notificationManager =
MyApp.appContext.
getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.cancel(notificationId)

this as well on mqtt disconnect, but still notification is not removing. 

MqttException on Android 12

Hello, I installed your library, a new error started popping up, here it is:

exception MqttException is never thrown in body of corresponding try statement

There was no such problem before changing the library to yours, but I cannot refuse it, so it is necessary that the application works on android 12, so I ask you to help.

[Solved] Cannot perform this operation because the connection pool has been closed.

Hello, I have received this crash on firebase.

So How can I void this crash?

Version: com.github.hannesa2:paho.mqtt.android:3.3.1

org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.5



Fatal Exception: java.lang.IllegalStateException: Cannot perform this operation because the connection pool has been closed.
       at android.database.sqlite.SQLiteConnectionPool.throwIfClosedLocked(SQLiteConnectionPool.java:962)
       at android.database.sqlite.SQLiteConnectionPool.waitForConnection(SQLiteConnectionPool.java:599)
       at android.database.sqlite.SQLiteConnectionPool.acquireConnection(SQLiteConnectionPool.java:348)
       at android.database.sqlite.SQLiteSession.acquireConnection(SQLiteSession.java:894)
       at 
android.database.sqlite.SQLiteSession.executeForChangedRowCount(SQLiteSession.java:752)
       at android.database.sqlite.SQLiteStatement.executeUpdateDelete(SQLiteStatement.java:64)
       at androidx.sqlite.db.framework.FrameworkSQLiteStatement.executeUpdateDelete(FrameworkSQLiteStatement.java:46)
       at info.mqtt.android.service.room.MqMessageDao_Impl.deleteClientHandle(MqMessageDao_Impl.java:229)
       at info.mqtt.android.service.MqttConnection.connect(MqttConnection.java:105)
       at info.mqtt.android.service.MqttService.connect(MqttService.java:289)
       at info.mqtt.android.service.MqttAndroidClient.doConnect(MqttAndroidClient.java:253)
       at info.mqtt.android.service.MqttAndroidClient.access$doConnect(MqttAndroidClient.java:39)
       at info.mqtt.android.service.MqttAndroidClient$MyServiceConnection.onServiceConnected(MqttAndroidClient.java:1264)
       at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1478)
       at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1495)
       at android.os.Handler.handleCallback(Handler.java:754)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at android.os.Looper.loop(Looper.java:165)
       at android.app.ActivityThread.main(ActivityThread.java:6375)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:802)

Screen Shot 2021-12-02 at 15 35 17

How to remove notification from status bar?

I have attached a notification when starting the service like below

mqttClient!!.setForegroundService(notification.build(), notificationId)

Now my issue is when I disconnect and close the mqtt connection still notification not removed from the status bar. Please suggest how can I remove that notification after mqtt disconnection.

StrictMode policy DiskWrite/ReadViolation

Hi, after turning on StrictMode I encounter DiskWriteViolation and DiskReadViolation when a message arrives. Version 3.3.8 on Android 12 (many devices), MqttAndroidClient with setForegroundService. Probably write/read to disk (to the database) should be done on the work thread.

Code in Application.onCraate():

StrictMode.setThreadPolicy(
                StrictMode.ThreadPolicy.Builder()
                    .detectDiskReads()
                    .detectDiskWrites()
                    .detectNetwork()
                    .penaltyLog()
                    .build()
            )

Logs:

D/StrictMode: StrictMode policy violation; ~duration=15 ms: android.os.strictmode.DiskWriteViolation
        at android.os.StrictMode$AndroidBlockGuardPolicy.onWriteToDisk(StrictMode.java:1615)
        at android.database.sqlite.SQLiteConnection.applyBlockGuardPolicy(SQLiteConnection.java:1201)
        at android.database.sqlite.SQLiteConnection.execute(SQLiteConnection.java:706)
        at android.database.sqlite.SQLiteSession.beginTransactionUnchecked(SQLiteSession.java:321)
        at android.database.sqlite.SQLiteSession.beginTransaction(SQLiteSession.java:300)
        at android.database.sqlite.SQLiteDatabase.beginTransaction(SQLiteDatabase.java:572)
        at android.database.sqlite.SQLiteDatabase.beginTransactionNonExclusive(SQLiteDatabase.java:506)
        at androidx.sqlite.db.framework.FrameworkSQLiteDatabase.beginTransactionNonExclusive(FrameworkSQLiteDatabase.java:78)
        at androidx.room.RoomDatabase.internalBeginTransaction(RoomDatabase.java:570)
        at androidx.room.RoomDatabase.beginTransaction(RoomDatabase.java:555)
        at info.mqtt.android.service.room.MqMessageDao_Impl.deleteId(MqMessageDao_Impl.java:206)
        at info.mqtt.android.service.room.MqMessageDatabase.discardArrived(MqMessageDatabase.kt:37)
        at info.mqtt.android.service.MqttService.acknowledgeMessageArrival(MqttService.kt:491)
        at info.mqtt.android.service.MqttAndroidClient.messageArrivedAction(MqttAndroidClient.kt:1066)
        at info.mqtt.android.service.MqttAndroidClient.onReceive(MqttAndroidClient.kt:887)
        at androidx.localbroadcastmanager.content.LocalBroadcastManager.executePendingBroadcasts(LocalBroadcastManager.java:313)
        at androidx.localbroadcastmanager.content.LocalBroadcastManager$1.handleMessage(LocalBroadcastManager.java:121)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loopOnce(Looper.java:201)
        at android.os.Looper.loop(Looper.java:288)
        at android.app.ActivityThread.main(ActivityThread.java:7839)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:550)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
StrictMode policy violation; ~duration=14 ms: android.os.strictmode.DiskReadViolation
        at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1659)
        at android.database.sqlite.SQLiteConnection.applyBlockGuardPolicy(SQLiteConnection.java:1199)
        at android.database.sqlite.SQLiteConnection.execute(SQLiteConnection.java:706)
        at android.database.sqlite.SQLiteSession.endTransactionUnchecked(SQLiteSession.java:439)
        at android.database.sqlite.SQLiteSession.endTransaction(SQLiteSession.java:403)
        at android.database.sqlite.SQLiteDatabase.endTransaction(SQLiteDatabase.java:589)
        at androidx.sqlite.db.framework.FrameworkSQLiteDatabase.endTransaction(FrameworkSQLiteDatabase.java:94)
        at androidx.room.RoomDatabase.internalEndTransaction(RoomDatabase.java:594)
        at androidx.room.RoomDatabase.endTransaction(RoomDatabase.java:584)
        at info.mqtt.android.service.room.MqMessageDao_Impl.deleteId(MqMessageDao_Impl.java:212)
        at info.mqtt.android.service.room.MqMessageDatabase.discardArrived(MqMessageDatabase.kt:37)
        at info.mqtt.android.service.MqttService.acknowledgeMessageArrival(MqttService.kt:491)
        at info.mqtt.android.service.MqttAndroidClient.messageArrivedAction(MqttAndroidClient.kt:1066)
        at info.mqtt.android.service.MqttAndroidClient.onReceive(MqttAndroidClient.kt:887)
        at androidx.localbroadcastmanager.content.LocalBroadcastManager.executePendingBroadcasts(LocalBroadcastManager.java:313)
        at androidx.localbroadcastmanager.content.LocalBroadcastManager$1.handleMessage(LocalBroadcastManager.java:121)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loopOnce(Looper.java:201)
        at android.os.Looper.loop(Looper.java:288)
        at android.app.ActivityThread.main(ActivityThread.java:7839)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:550)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)

[Crash] java.lang.NullPointerException

Hello,

I am getting a null pointer exception when checking for IMqttToken's exception. According to the comments in IMqttToken.java if the action that returns IMqttToken finished successfully it should return null, however, currently it throws null pointer exception.

Can be replicated by utilizing the following ActionListener:
image

Changing the getException function in MqttTokenAndroid class to the following should fix the issue
override fun getException(): MqttException? { return lastException }

java.lang.NullPointerException at info.mqtt.android.service.MqttTokenAndroid.getException(MqttTokenAndroid.kt:75)

Why aren't lower android versions supported? + Timber Error

I switched to this library to support Android 12+.

My app has minSDK 19 and targetSDK 21. This library has minSDK 21 so the Manifest merger fails when using it in my app.

To overcome this I manually edited the AndroidManifest.xml in this libraries aar file (locally).

I then got an error like NoClassDef found for Timber.
So I manually imported Timber using
implementation 'com.jakewharton.timber:timber:5.0.1

After this the library seems to work well on lower and higher android versions.

Is there any reason this library doesn't support lower android versions?

You need to use a Theme.AppCompat theme

Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
        at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:852)
        at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:815)
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:703)
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:195)
        at androidx.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:303)
        at androidx.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:284)

Getting this error while using the latest aar file of the 3.3.7 version.

Gradle dependency:

implementation files('libs/mqtt.aar')

MQTT helper class:

`class MqttHelper(var context: Context, subscriptionTopic: String, subscriptionTopicPresence: String) {
lateinit var mqttAndroidClient: MqttAndroidClient

internal val serverUri = BuildConfig.MQTT_URL

internal val subscriptionTopic = subscriptionTopic
internal val presenceSubscriptionTopic = subscriptionTopicPresence
internal val username = BuildConfig.MQTT_USER
internal val password = BuildConfig.MQTT_PASSWORD

init {
    try {
        mqttAndroidClient = MqttAndroidClient(context, serverUri, generateMqttClientID())
        mqttAndroidClient.setCallback(object : MqttCallbackExtended {
            override fun connectComplete(b: Boolean, s: String) {
                Log.e("MQTT", "Connect Complete: "+s)
            }

            override fun connectionLost(throwable: Throwable?) {
                androidx.localbroadcastmanager.content.LocalBroadcastManager.getInstance(context).sendBroadcast(Intent(
                    Constant.MQTT_CONNECTION_LOST))
                throwable?.let {
                    Log.e("MQTT", "Helper Class connection lost: $serverUri$throwable")
                }
                connect()
            }

            @kotlin.jvm.Throws(Exception::class)
            override fun messageArrived(topic: String?, mqttMessage: MqttMessage?) {
                var intentMsg = Intent(Constant.MQTT_MESSAGE_PAYLOAD)
                intentMsg.putExtra(Constant.KEY_TOPIC, topic)
                intentMsg.putExtra(Constant.KEY_PAYLOAD, mqttMessage?.payload)

// Log.e("mqtt message", mqttMessage.payload.toString())
androidx.localbroadcastmanager.content.LocalBroadcastManager.getInstance(context).sendBroadcast(intentMsg)
}

            override fun deliveryComplete(iMqttDeliveryToken: IMqttDeliveryToken?) {}
        })
        connect()
    } catch (e: Exception) {
        e.printStackTrace()
    }
}


private fun generateMqttClientID(): String{
    return "android" + System.nanoTime()
}

/**
 * This method will set the callback to the mqtt client
 */
fun setCallback(callback: MqttCallbackExtended) {
    try {
        mqttAndroidClient.setCallback(callback)
    } catch (e: NullPointerException) {
        e.printStackTrace()
    } catch (e: Exception) {
        e.printStackTrace()
    }
}

/**
 * This method will connect the mqtt
 */
private fun connect() {
    try {

        val mqttConnectOptions = MqttConnectOptions()
        mqttConnectOptions.isAutomaticReconnect = true
        mqttConnectOptions.isCleanSession = true
        mqttConnectOptions.userName = username
        mqttConnectOptions.password = password.toCharArray()


        if(BuildConfig.FLAVOR == "envProd") {
            try {
                val caCrtFile = context.resources.openRawResource(R.raw.ca)
                val sslSocketFactory = getSingleSocketFactory(caCrtFile)
                mqttConnectOptions.socketFactory = sslSocketFactory
            } catch (e: Exception) {
                AppLog.e("MQTT", e)
            }
        }


        mqttAndroidClient.connect(mqttConnectOptions, context, object : IMqttActionListener {
            override fun onSuccess(asyncActionToken: IMqttToken) {
                androidx.localbroadcastmanager.content.LocalBroadcastManager.getInstance(context).sendBroadcast(Intent(Constant.MQTT_CONNECTION_SUCCESS))
                val disconnectedBufferOptions = DisconnectedBufferOptions()
                disconnectedBufferOptions.isBufferEnabled = true
                disconnectedBufferOptions.bufferSize = 100
                disconnectedBufferOptions.isPersistBuffer = false
                disconnectedBufferOptions.isDeleteOldestMessages = false
                mqttAndroidClient.setBufferOpts(disconnectedBufferOptions)
                Log.e("MQTT", "connected")
                subscribeToTopic()
            }

            override fun onFailure(asyncActionToken: IMqttToken, exception: Throwable) {
                androidx.localbroadcastmanager.content.LocalBroadcastManager.getInstance(context).sendBroadcast(Intent(Constant.MQTT_CONNECTION_FAILURE))
                Log.e("MQTT", "Failed to connect to: " + serverUri + exception.toString())
            }
        })


    } catch (ex: MqttException) {
        ex.printStackTrace()
        Log.e("MQTT", ex.toString())
    } catch (e: Exception) {
        e.printStackTrace()
        Log.e("MQTT", e.toString())
    }

}

/**
 * This method will subscribe to the topic to the mqtt client
 */
private fun subscribeToTopic() {
    try {
        mqttAndroidClient.subscribe(subscriptionTopic, 0, context, object : IMqttActionListener {
            override fun onSuccess(asyncActionToken: IMqttToken) {
                androidx.localbroadcastmanager.content.LocalBroadcastManager.getInstance(context).sendBroadcast(Intent(Constant.MQTT_SUBSCRIBE_SUCCESS))
            }

            override fun onFailure(asyncActionToken: IMqttToken, exception: Throwable) {
                androidx.localbroadcastmanager.content.LocalBroadcastManager.getInstance(context).sendBroadcast(Intent(Constant.MQTT_SUBSCRIBE_FAILURE))
            }
        })
        mqttAndroidClient.subscribe(presenceSubscriptionTopic, 0, context, object : IMqttActionListener {
            override fun onSuccess(asyncActionToken: IMqttToken) {
                androidx.localbroadcastmanager.content.LocalBroadcastManager.getInstance(context).sendBroadcast(Intent(Constant.MQTT_SUBSCRIBE_SUCCESS))
            }

            override fun onFailure(asyncActionToken: IMqttToken, exception: Throwable) {
                androidx.localbroadcastmanager.content.LocalBroadcastManager.getInstance(context).sendBroadcast(Intent(Constant.MQTT_SUBSCRIBE_FAILURE))
            }
        })
    } catch (ex: MqttException) {
        Log.e("MQTT", ex.toString())
        ex.printStackTrace()
    } catch (e: Exception) {
        e.printStackTrace()
        Log.e("MQTT", e.toString())
    }
}

/**
 * This method will unsubscribe to the topic to the mqtt client
 */
fun unSubscribeToTopic() {
    try {
        mqttAndroidClient.unsubscribe(subscriptionTopic, context, object : IMqttActionListener {
            override fun onSuccess(asyncActionToken: IMqttToken) {
                androidx.localbroadcastmanager.content.LocalBroadcastManager.getInstance(context).sendBroadcast(Intent(Constant.MQTT_UNSUBSCRIBE_SUCCESS))
            }

            override fun onFailure(asyncActionToken: IMqttToken, exception: Throwable) {
                androidx.localbroadcastmanager.content.LocalBroadcastManager.getInstance(context).sendBroadcast(Intent(Constant.MQTT_UNSUBSCRIBE_FAILURE))
            }
        })

        mqttAndroidClient.unsubscribe(presenceSubscriptionTopic, context, object : IMqttActionListener {
            override fun onSuccess(asyncActionToken: IMqttToken) {
                androidx.localbroadcastmanager.content.LocalBroadcastManager.getInstance(context).sendBroadcast(Intent(Constant.MQTT_UNSUBSCRIBE_SUCCESS))
            }

            override fun onFailure(asyncActionToken: IMqttToken, exception: Throwable) {
                androidx.localbroadcastmanager.content.LocalBroadcastManager.getInstance(context).sendBroadcast(Intent(Constant.MQTT_UNSUBSCRIBE_FAILURE))
            }
        })

    } catch (ex: MqttException) {
        System.err.println("Exception subscribing")
        Log.e("MQTT", ex.toString())
        ex.printStackTrace()
    } catch (e: Exception) {
        e.printStackTrace()
        Log.e("MQTT", e.toString())
    }
}

/**
 * This method will disconnect the mqtt client
 */
fun disconnectClient() {
    mqttAndroidClient.unregisterResources()
    mqttAndroidClient.close()
}

@kotlin.jvm.Throws(java.lang.Exception::class)
fun getSingleSocketFactory(caCrtFileInputStream: InputStream?): SSLSocketFactory? {
    Security.addProvider(BouncyCastleProvider())
    var caCert: java.security.cert.Certificate? = null
    val bis = BufferedInputStream(caCrtFileInputStream)
    val cf: CertificateFactory = CertificateFactory.getInstance("X.509")
    while (bis.available() > 0) {
        caCert = cf.generateCertificate(bis)
    }
    val caKs: KeyStore = KeyStore.getInstance(KeyStore.getDefaultType())
    caKs.load(null, null)
    caKs.setCertificateEntry("cert-certificate", caCert)
    val tmf: TrustManagerFactory =
        TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm())
    tmf.init(caKs)
    val sslContext: SSLContext = SSLContext.getInstance("TLSv1.2")
    sslContext.init(null, tmf.trustManagers, null)
    return sslContext.socketFactory
}

@kotlin.jvm.Throws(java.lang.Exception::class)
fun getSocketFactory(
    caCrtFile: InputStream?, crtFile: InputStream?, keyFile: InputStream?,
    password: String
): SSLSocketFactory? {
    Security.addProvider(BouncyCastleProvider())

    // load CA certificate
    var caCert: java.security.cert.Certificate? = null
    var bis = BufferedInputStream(caCrtFile)
    val cf = CertificateFactory.getInstance("X.509")
    while (bis.available() > 0) {
        caCert = cf.generateCertificate(bis)
    }

    // load client certificate
    bis = BufferedInputStream(crtFile)
    var cert: java.security.cert.Certificate? = null
    while (bis.available() > 0) {
        cert = cf.generateCertificate(bis)
    }

    // load client private cert
    val pemParser = PEMParser(InputStreamReader(keyFile))
    val pemParserObj = pemParser.readObject()
    val converter = JcaPEMKeyConverter().setProvider("BC")
    val key: KeyPair = converter.getKeyPair(pemParserObj as PEMKeyPair)
    val caKs = KeyStore.getInstance(KeyStore.getDefaultType())
    caKs.load(null, null)
    caKs.setCertificateEntry("cert-certificate", caCert)
    val tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm())
    tmf.init(caKs)
    val ks = KeyStore.getInstance(KeyStore.getDefaultType())
    ks.load(null, null)
    ks.setCertificateEntry("certificate", cert)
    ks.setKeyEntry(
        "private-cert",
        key.getPrivate(),
        password.toCharArray(),
        arrayOf<java.security.cert.Certificate?>(cert)
    )
    val kmf: KeyManagerFactory =
        KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm())
    kmf.init(ks, password.toCharArray())
    val context = SSLContext.getInstance("TLSv1.2")
    context.init(kmf.keyManagers, tmf.trustManagers, null)
    return context.socketFactory
}

}
`

Usage:

val mqttHelper = MqttHelper(requireContext(), subscriptionChannel, subscriptionChannelPresence)

Fatal Exception: java.lang.Throwable: No Throwable given

Fatal Exception: java.lang.Throwable: No Throwable given {.invocationContext=null, .errorMessage=not connected, .activityToken=504, .callbackAction=send, .clientHandle=tcp://m1-mqtt-broker.blowhorn.com:1883:driver_52598:net.blowhorn.driverapp, .callbackStatus=ERROR} at info.mqtt.android.service.MqttAndroidClient.simpleAction(MqttAndroidClient.kt:1000) at info.mqtt.android.service.MqttAndroidClient.sendAction(MqttAndroidClient.kt:1016) at info.mqtt.android.service.MqttAndroidClient.onReceive(MqttAndroidClient.kt:893) at androidx.localbroadcastmanager.content.LocalBroadcastManager.executePendingBroadcasts(LocalBroadcastManager.java:313) at androidx.localbroadcastmanager.content.LocalBroadcastManager$1.handleMessage(LocalBroadcastManager.java:121) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:254) at android.app.ActivityThread.main(ActivityThread.java:8243) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:612) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1006)

   What issue is this?

room database error

hello,hannesa2:
I use your fork.
2022-01-15 10:31:35.879 10342-10831/com.philips.easykey.lock E/SQLiteLog: (1) no such table: room_table_modification_log in "SELECT * FROM room_table_modification_log WHERE invalidated = 1;"
2022-01-15 10:31:35.881 10342-10831/com.philips.easykey.lock E/ROOM: Cannot run invalidation tracker. Is the db closed?
android.database.sqlite.SQLiteException: no such table: room_table_modification_log (code 1 SQLITE_ERROR): , while compiling: SELECT * FROM room_table_modification_log WHERE invalidated = 1;
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1047)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:654)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:590)
at android.database.sqlite.SQLiteProgram.(SQLiteProgram.java:62)
at android.database.sqlite.SQLiteQuery.(SQLiteQuery.java:37)
at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:46)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1546)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1521)
at androidx.sqlite.db.framework.FrameworkSQLiteDatabase.query(FrameworkSQLiteDatabase.java:183)
at androidx.room.RoomDatabase.query(RoomDatabase.java:530)
at androidx.room.RoomDatabase.query(RoomDatabase.java:513)
at androidx.room.InvalidationTracker$1.checkUpdatedTable(InvalidationTracker.java:458)
at androidx.room.InvalidationTracker$1.run(InvalidationTracker.java:431)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)

please help me

Can't include library in my project

Apologies for raising this here.

I am trying to add MQTT functionality to an existing app but can't for the life of me work out how to include this library. I'm using android studio bumblebee.

I've tried importing serviceLibrary but that doesn't work. I'm quite new to Android development (but not development) any help would be most appreciated.

Thanks

Kieran

MqttAndroidClient override wrong disconnect function

In disconnect functions interface they specfify userContext object is nullable, but it become non null in MqttAndroidClient implementation class

userContext – optional object used to pass context to the callback. Use null if not required.
callback – optional listener that will be notified when the disconnect completes. Use null if not required.

IMqttToken disconnect(long quiesceTimeout, Object userContext, IMqttActionListener callback) throws MqttException;

MqttAndroidClient class code:

override fun disconnect(quiesceTimeout: Long, userContext: Any, callback: IMqttActionListener): IMqttToken

publish returns a token with messageId = 0

Hello, here is my problem:
In case there's currently no connection, if I call publish, it returns a token with no message id (0).
After this, when the connection returns, the previous message gets correctly delivered, and I receive a deliveryComplete callback with a token containing the correct messageId, but since I didn't receive the correct one during publish, I have no means to compare them and recognize the message that was just delivered.

I noticed that in the function

MqttAndroidClient.kt

override fun publish(topic: String, payload: ByteArray, qos: Int, retained: Boolean, userContext: Any?, callback: IMqttActionListener?): IMqttDeliveryToken {

the variable activityToken always contains what I need, but 'token', the value returned in the end, doesn't contain that in this particular case.

Am I doing something wrong? I thought publish would return the correct messageId no matter the current connection status.
Thank you

Build failure (compileSdkVersion mismatch)

Hi, I have a build failure in my application with targeting sdk 30 :

Execution failed for task ':app:checkDevDebugAarMetadata'.
> Multiple task action failures occurred:
   > A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
      > The minCompileSdk (31) specified in a
        dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
        is greater than this module's compileSdkVersion (android-30).
        Dependency: androidx.room:room-runtime:2.4.0-beta01.
        AAR metadata file: /Users/julienherrero/.gradle/caches/transforms-2/files-2.1/0f004f8c9da1c9927b8ee43b32c83da3/room-runtime-2.4.0-beta01/META-INF/com/android/build/gradle/aar-metadata.properties.
   > A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
      > The minCompileSdk (31) specified in a
        dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
        is greater than this module's compileSdkVersion (android-30).
        Dependency: androidx.sqlite:sqlite-framework:2.2.0-beta01.
        AAR metadata file: /Users/julienherrero/.gradle/caches/transforms-2/files-2.1/269bc7585f32eb9ff4a005f447477511/sqlite-framework-2.2.0-beta01/META-INF/com/android/build/gradle/aar-metadata.properties.
   > A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
      > The minCompileSdk (31) specified in a
        dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
        is greater than this module's compileSdkVersion (android-30).
        Dependency: androidx.sqlite:sqlite:2.2.0-beta01.
        AAR metadata file: /Users/julienherrero/.gradle/caches/transforms-2/files-2.1/96d92039dca23efc34737efd10d022ad/sqlite-2.2.0-beta01/META-INF/com/android/build/gradle/aar-metadata.properties.

I found a workaround to fix this error (in my app) :

configurations.all {
    resolutionStrategy {
        force 'androidx.room:room-runtime:2.3.0'
        force 'androidx.sqlite:sqlite-framework:2.1.0'
        force 'androidx.sqlite:sqlite:2.1.0'
    }
}

But is it not too restrictive to force using sdk 31 ?
I know it's better to target the most recent sdk API, but I have some restriction to migrate for know (storage issues).

And is it really mandatory to use beta dependencies instead of stable versions ?

Thanks for your work anyway !

Manifest [FILE_PROVIDER] merger failed

In my manifest i have on FILE_PROVIDER that i use to share some images..
So when i build my project i'm getting some error message:

Manifest merger failed Attribute meta-data#android.support.FILE_PROVIDER_PATHS@resource value=(@xml/provider_path) is also present at [com.github.AppDevNext.Logcat:LogcatCoreLib:2.9.4]

I'm current using the version: 3.4.0-beta5

Some work around to this is just add tools:replace="android:resource in meta data of FILE_PROVIDER
but is there any problem to that?

Thanks!

ReadMe's instruction does not work with the latest Android Studio.

All the instruction available is the thing at the bottom. However it does not seem to work with default project template created by the latest Android Studio. After struggling with errors, I have found a solution. It was adding the following to settings.gradle file

maven { url 'https://jitpack.io' }

below other repositories. Please add that to the instruction so that people would not waste time as I did.


  allprojects {
    repositories {
      ...
      maven { url 'https://jitpack.io' }
    }
  }
dependencies {
  implementation 'androidx.legacy:legacy-support-v4:1.0.0'
  implementation 'com.github.hannesa2:paho.mqtt.android:$latestVersion'
}

not using foreground service

Hi there
I just migrated to this lib and i have an android version 12, though I don't use this as a foreground service, meening I am not setting the client like this: client.setForegroundService(..)
and it looks like everything is working fine.

am i missing something? is it not mandatory to use it as a foreground service?

thanks

Problem with WorkManager

Since we use version 3.4.0-beta2 with WorkManager we have a job limit problem :

java.lang.IllegalStateException: Apps may not schedule more than 100 distinct jobs
    at android.os.Parcel.createExceptionOrNull(Parcel.java:2381)
    at android.os.Parcel.createException(Parcel.java:2357)
    at android.os.Parcel.readException(Parcel.java:2340)
    at android.os.Parcel.readException(Parcel.java:2282)
    at android.app.job.IJobScheduler$Stub$Proxy.schedule(IJobScheduler.java:308)
    at android.app.JobSchedulerImpl.schedule(JobSchedulerImpl.java:47)
    at androidx.work.impl.background.systemjob.SystemJobScheduler.scheduleInternal(SystemJobScheduler.java:187)
    at androidx.work.impl.background.systemjob.SystemJobScheduler.schedule(SystemJobScheduler.java:133)
    at androidx.work.impl.Schedulers.schedule(Schedulers.java:108)
    at androidx.work.impl.utils.ForceStopRunnable.forceStopRunnable(ForceStopRunnable.java:226)
    at androidx.work.impl.utils.ForceStopRunnable.run(ForceStopRunnable.java:110)
    at androidx.work.impl.utils.SerialExecutor$Task.run(SerialExecutor.java:91)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    at java.lang.Thread.run(Thread.java:923)
java.lang.IllegalStateException: JobScheduler 100 job limit exceeded.  We count 100 WorkManager jobs in JobScheduler; we have 3 tracked jobs in our DB; our Configuration limit is 20.
    at androidx.work.impl.background.systemjob.SystemJobScheduler.scheduleInternal(SystemJobScheduler.java:218)
    at androidx.work.impl.background.systemjob.SystemJobScheduler.schedule(SystemJobScheduler.java:133)
    at androidx.work.impl.Schedulers.schedule(Schedulers.java:108)
    at androidx.work.impl.utils.ForceStopRunnable.forceStopRunnable(ForceStopRunnable.java:226)
    at androidx.work.impl.utils.ForceStopRunnable.run(ForceStopRunnable.java:110)
    at androidx.work.impl.utils.SerialExecutor$Task.run(SerialExecutor.java:91)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    at java.lang.Thread.run(Thread.java:923)

Do you have any idea why it does that?

android.database.sqlite.SQLiteConnection.nativeExecute

I found this problem on my app
1 android.database.sqlite.SQLiteConnection.nativeExecute(Native Method) 2 android.database.sqlite.SQLiteConnection.execute(SQLiteConnection.java:556) 3 android.database.sqlite.SQLiteSession.endTransactionUnchecked(SQLiteSession.java:437) 4 android.database.sqlite.SQLiteSession.endTransaction(SQLiteSession.java:401) 5 android.database.sqlite.SQLiteDatabase.endTransaction(SQLiteDatabase.java:551) 6 androidx.sqlite.db.framework.FrameworkSQLiteDatabase.endTransaction(FrameworkSQLiteDatabase.java:94) 7 androidx.room.RoomDatabase.internalEndTransaction(RoomDatabase.java:594) 8 androidx.room.RoomDatabase.endTransaction(RoomDatabase.java:584) 9 info.mqtt.android.service.room.MqMessageDao_Impl.deleteId(MqMessageDao_Impl.java:212) 10 info.mqtt.android.service.room.MqMessageDatabase.discardArrived(MqMessageDatabase.kt:37) 11 info.mqtt.android.service.MqttService.acknowledgeMessageArrival(MqttService.kt:491) 12 info.mqtt.android.service.MqttAndroidClient.messageArrivedAction(MqttAndroidClient.kt:1066) 13 info.mqtt.android.service.MqttAndroidClient.onReceive(MqttAndroidClient.kt:887) 14 androidx.localbroadcastmanager.content.LocalBroadcastManager.executePendingBroadcasts(LocalBroadcastManager.java:313) 15 androidx.localbroadcastmanager.content.LocalBroadcastManager$1.handleMessage(LocalBroadcastManager.java:121) 16 android.os.Handler.dispatchMessage(Handler.java:106) 17 android.os.Looper.loop(Looper.java:164) 18 android.app.ActivityThread.main(ActivityThread.java:6494) 19 java.lang.reflect.Method.invoke(Native Method) 20 com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)

SQLite Crash in v3.3.2

Fatal Exception: java.lang.IllegalStateException: Cannot perform this operation because the connection pool has been closed. at android.database.sqlite.SQLiteConnectionPool.throwIfClosedLocked(SQLiteConnectionPool.java:962) at android.database.sqlite.SQLiteConnectionPool.waitForConnection(SQLiteConnectionPool.java:599) at android.database.sqlite.SQLiteConnectionPool.acquireConnection(SQLiteConnectionPool.java:348) at android.database.sqlite.SQLiteSession.acquireConnection(SQLiteSession.java:894) at android.database.sqlite.SQLiteSession.executeForChangedRowCount(SQLiteSession.java:752) at android.database.sqlite.SQLiteStatement.executeUpdateDelete(SQLiteStatement.java:64) at androidx.sqlite.db.framework.FrameworkSQLiteStatement.executeUpdateDelete(FrameworkSQLiteStatement.java:46) at info.mqtt.android.service.room.MqMessageDao_Impl.deleteClientHandle(MqMessageDao_Impl.java:229) at info.mqtt.android.service.MqttConnection.connect(MqttConnection.kt:105) at info.mqtt.android.service.MqttService.connect(MqttService.kt:289) at info.mqtt.android.service.MqttAndroidClient.doConnect(MqttAndroidClient.kt:253) at info.mqtt.android.service.MqttAndroidClient.access$doConnect(MqttAndroidClient.kt:39) at info.mqtt.android.service.MqttAndroidClient$MyServiceConnection.onServiceConnected(MqttAndroidClient.kt:1267) at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1461) at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1489) at android.os.Handler.handleCallback(Handler.java:754) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:163) at android.app.ActivityThread.main(ActivityThread.java:6393) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:933) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)

Why is it happening? Please check this. Thanks

Security Exception in A12

Getting exception:
Fatal Exception: java.lang.SecurityException: Caller xxx needs to hold android.permission.SCHEDULE_EXACT_ALARM to set exact alarms.

on line 86 in AlarmPingSender.kt
alarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, nextAlarmInMilliseconds, pendingIntent)

Happens on A12 devices only if, Alarms & Reminders permission is turned off. Doc: link

Unable to connect to server : ECONNREFUSED (Connection refused)

I was trying to run the basicSample project with the following server URI : tcp://0.0.0.0:1883. But it gives the following error

Unable to connect to server token: Unable to connect to server (32103) - java.net.ConnectException: failed to connect to localhost/127.0.0.1 (port 1883) from /127.0.0.1 (port 46218) after 30000ms: isConnected failed: ECONNREFUSED (Connection refused)

Any idea why is this happening?

A question about the use of mqtt QoS2 .

Sorry to bother you,my friend,
When I use MQTT Qos2, the publisher publish a msg to the Broker.I can get the result from PUBCOMP response.Is there a method to get a response from PUBREC ? Because I want to know if my message was sent successfully。
Please see the picture below and Thank you very much.
image

Ability to construct MqttAndroidClient with specific MqttClientPersistence

Hello, thank you for maintaining this library. I have a use case where I need to be able to specify MemoryPersistence on the MqttAndroidClient. In the old version of the Eclipse library this was a constructor parameter, but in the latest version of this library it is a private var and not possible to access. Without MemoryPersistence we run into an error after connecting to our server.

Do you think it would it be possible to move this property to a constructor parameter? It could still have a default value of null to utilize the behavior that exists in MqttConnection.kt, though it would be nice to be able to explicitly set MemoryPersistence (and maybe there are other use cases opened up by giving the client control over which class of persistence is used).

about qos level question

What I understand is that when QoS = 2, the data pushed by the Android client will timeout when the network is disconnected and will be pushed again after the network is restored.
However, in actual use, I found that some mobile phones will not push again after the network is restored.
Why does this happen?

Error in import org.eclipse.paho.android.service.MqttAndroidClient

Hi,
After adding .aar files and also removed "org.eclipse.paho:org.eclipse.paho.android.service:1.1.1", Getting error in import org.eclipse.paho.android.service.MqttAndroidClient;. Also tried to import info.mqtt.android.service.MqttAndroidClient as per your instructions in https://stackoverflow.com/questions/71155187/android-paho-mqtt-crashes-android-12-targeting-s-version-31-and-above-requi/71404563.
Please help me out...
Thanks in Advance.
List of error
Cannot resolve symbol 'MqttAndroidClient'
Cannot resolve method 'isConnected()'
Cannot resolve method 'disconnect()'
Cannot resolve method 'subscribe(java.lang.String, int, null, anonymous org.eclipse.paho.client.mqttv3.IMqttActionListener)'
Cannot resolve method 'publish(java.lang.String, org.eclipse.paho.client.mqttv3.MqttMessage)'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.