Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notification is not removing when we set setForegroundService in mqtt client #258

Open
Monika-Paliwal opened this issue Dec 10, 2021 · 12 comments · May be fixed by #444
Open

Notification is not removing when we set setForegroundService in mqtt client #258

Monika-Paliwal opened this issue Dec 10, 2021 · 12 comments · May be fixed by #444

Comments

@Monika-Paliwal
Copy link

Monika-Paliwal commented Dec 10, 2021

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.

@Monika-Paliwal Monika-Paliwal changed the title Notification is not removing when we set setForegroundService in mqtt clien Notification is not removing when we set setForegroundService in mqtt client Dec 10, 2021
@hannesa2
Copy link
Owner

I guess you have to do something like this https://stackoverflow.com/a/35721582/1079990

@Monika-Paliwal
Copy link
Author

No, We are using below mentioned code in kotlin class so need a solution for stop mqttClient service
mqttClient!!.setForegroundService(notification.build(),notificationId)`
if we are using this.stopForeground(true) then it will show create member function.

@stale
Copy link

stale bot commented Jan 7, 2023

This issue has been automatically marked as stale because it has not had recent activity. Please comment here if it is still valid so that we can reprioritize. Thank you!

@hannesa2
Copy link
Owner

Sorry for the late response.
Please use https://github.com/hannesa2/paho.mqtt.android/releases/tag/3.6.0-beta7 and please tell me, how it works after several connect/disconnect. I didn't tested this.

@stale stale bot removed the stale label Apr 11, 2023
@Elswah
Copy link

Elswah commented Jan 11, 2024

still have issue of this , removing notification after disconnect

@NinaTietje
Copy link

Hey Hannes, I searched for an already working solution to remove the foreground notification for the 3.x versions.
So I tested the 3.6.0beta7 branch with the extendedSample. Showing and removing the notification via the connection switch is working fine, but it doesn't really reconnect and messages can't be received. Only after an app kill and restart the connect via the connection switch would work (but only for the first time after the app started).
I also tested adding the changes from here #560 to 3.6.3. Here the reconnect works all the time, all messages are received. Using the connection switch the notification will be removed but not shown again except when the connection has been terminated AND the app was killed before. Just killing the app doesn' t remove the notification.
Maybe you have an idea how to improve #560

@hannesa2
Copy link
Owner

hannesa2 commented Apr 3, 2024

Hi, you mean we should apply #560 on 3.x branch as well ?
Not sure if it will work, when we do something on onTerminate() of application.

To be honest, I would put afford to 4.x. May I ask you, why you still using 3.x ?

@NinaTietje
Copy link

Yes, that's what I meant. But just the changes from #560 would not be enough to work completely fine.

Sure, I rely on receiving messages and displaying notifications while the device is asleep and currently this is only working well on the 3.x versions. On the 4.x versions (with started foreground service) the connection will be lost after a few minutes and it won't reconnect while the device is asleep. (Also tested with the extendedSample from 4.2.4)

@NinaTietje
Copy link

Found out that #560 already works fine (only in the extendedSample something seemed to be missing).
I would be very grateful if you could add a release for 3.x with it or just a beta version. I know at some point the foreground service will become obsolete and I still want to find out why the workmanager solution for 4.x doesn't work completely.

@hannesa2
Copy link
Owner

hannesa2 commented Apr 3, 2024

Here is the release https://github.com/hannesa2/paho.mqtt.android/releases/tag/3.6.4

I still want to find out why the workmanager solution for 4.x doesn't work completely.

I'm looking forward for your help

@hannesa2
Copy link
Owner

hannesa2 commented Apr 4, 2024

@NinaTietje
I did a 4.x test drive on a real device and lock device. But I'm not sure if device falls asleep during USB debugging.
I never see a lost connection and for me it looks not wrong
image

@hannesa2
Copy link
Owner

hannesa2 commented Apr 4, 2024

Without debugging I see with built in logcat view
image
this error

I: (MqttCallbackHandler.kt:32)(10231): .messageArrived(): [B@2813483 test qos=0 retained:false
V: (MqttAndroidClient.kt:889)(10231): .onReceive(): Bundle[{destinationName=test, messageId=5ddc013b-4ea3-4e65-b1e7-a40e67cf0684, .PARCEL=36.30, .callbackAction=messageArrived, .clientHandle=tcp://broker.hivemq.com:1883:ExtendedSampleClient:info.mqtt.android.extsample, .callbackStatus=OK}]
I: (MqttCallbackHandler.kt:32)(10231): .messageArrived(): [B@5576e39 test qos=0 retained:false
V: (MqttAndroidClient.kt:889)(10231): .onReceive(): Bundle[{.exceptionStack=Verbindung wurde getrennt (32109) - java.net.SocketException: Software caused connection abort
V: (MqttAndroidClient.kt:889)(10231): 	at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:197)
V: (MqttAndroidClient.kt:889)(10231): 	at java.lang.Thread.run(Thread.java:1012)
V: (MqttAndroidClient.kt:889)(10231): Caused by: java.net.SocketException: Software caused connection abort
V: (MqttAndroidClient.kt:889)(10231): 	at java.net.SocketInputStream.socketRead0(Native Method)
V: (MqttAndroidClient.kt:889)(10231): 	at java.net.SocketInputStream.socketRead(SocketInputStream.java:118)
V: (MqttAndroidClient.kt:889)(10231): 	at java.net.SocketInputStream.read(SocketInputStream.java:173)
V: (MqttAndroidClient.kt:889)(10231): 	at java.net.SocketInputStream.read(SocketInputStream.java:143)
V: (MqttAndroidClient.kt:889)(10231): 	at java.net.SocketInputStream.read(SocketInputStream.java:205)
V: (MqttAndroidClient.kt:889)(10231): 	at java.io.DataInputStream.readByte(DataInputStream.java:273)
V: (MqttAndroidClient.kt:889)(10231): 	at org.eclipse.paho.client.mqttv3.internal.wire.MqttInputStream.readMqttWireMessage(MqttInputStream.java:92)
V: (MqttAndroidClient.kt:889)(10231): 	at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:137)
V: (MqttAndroidClient.kt:889)(10231): 	... 1 more
V: (MqttAndroidClient.kt:889)(10231): , .errorMessage=Verbindung wurde getrennt, .exception=Verbindung wurde getrennt (32109) - java.net.SocketException: Software caused connection abort, .callbackAction=onConnectionLost, .clientHandle=tcp://broker.hivemq.com:1883:ExtendedSampleClient:info.mqtt.android.extsample, .callbackStatus=OK}]
D: (MqttCallbackHandler.kt:17)(10231): .connectionLost(): Connection Lost: Verbindung wurde getrennt
D: VRI[MainActivity](10231): Start draw after previous draw not visible
I: ImeTracker(10231): info.mqtt.android.extsample:5820dd82: onRequestHide at ORIGIN_CLIENT_HIDE_SOFT_INPUT reason HIDE_SOFT_INPUT
I: ImeTracker(10231): info.mqtt.android.extsample:5820dd82: onFailed at PHASE_CLIENT_VIEW_SERVED
D: AutofillManager(10231): view not autofillable - not passing ime action check
```04-04 08:49:53.114 I: (MqttCallbackHandler.kt:32)(10231): .messageArrived(): [B@2813483 test qos=0 retained:false
V: (MqttAndroidClient.kt:889)(10231): .onReceive(): Bundle[{destinationName=test, messageId=5ddc013b-4ea3-4e65-b1e7-a40e67cf0684, .PARCEL=36.30, .callbackAction=messageArrived, .clientHandle=tcp://broker.hivemq.com:1883:ExtendedSampleClient:info.mqtt.android.extsample, .callbackStatus=OK}]
I: (MqttCallbackHandler.kt:32)(10231): .messageArrived(): [B@5576e39 test qos=0 retained:false
V: (MqttAndroidClient.kt:889)(10231): .onReceive(): Bundle[{.exceptionStack=Verbindung wurde getrennt (32109) - java.net.SocketException: Software caused connection abort
V: (MqttAndroidClient.kt:889)(10231): 	at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:197)
V: (MqttAndroidClient.kt:889)(10231): 	at java.lang.Thread.run(Thread.java:1012)
V: (MqttAndroidClient.kt:889)(10231): Caused by: java.net.SocketException: Software caused connection abort
V: (MqttAndroidClient.kt:889)(10231): 	at java.net.SocketInputStream.socketRead0(Native Method)
V: (MqttAndroidClient.kt:889)(10231): 	at java.net.SocketInputStream.socketRead(SocketInputStream.java:118)
V: (MqttAndroidClient.kt:889)(10231): 	at java.net.SocketInputStream.read(SocketInputStream.java:173)
V: (MqttAndroidClient.kt:889)(10231): 	at java.net.SocketInputStream.read(SocketInputStream.java:143)
V: (MqttAndroidClient.kt:889)(10231): 	at java.net.SocketInputStream.read(SocketInputStream.java:205)
V: (MqttAndroidClient.kt:889)(10231): 	at java.io.DataInputStream.readByte(DataInputStream.java:273)
V: (MqttAndroidClient.kt:889)(10231): 	at org.eclipse.paho.client.mqttv3.internal.wire.MqttInputStream.readMqttWireMessage(MqttInputStream.java:92)
V: (MqttAndroidClient.kt:889)(10231): 	at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:137)
V: (MqttAndroidClient.kt:889)(10231): 	... 1 more
V: (MqttAndroidClient.kt:889)(10231): , .errorMessage=Verbindung wurde getrennt, .exception=Verbindung wurde getrennt (32109) - java.net.SocketException: Software caused connection abort, .callbackAction=onConnectionLost, .clientHandle=tcp://broker.hivemq.com:1883:ExtendedSampleClient:info.mqtt.android.extsample, .callbackStatus=OK}]
D: (MqttCallbackHandler.kt:17)(10231): .connectionLost(): Connection Lost: Verbindung wurde getrennt
D: VRI[MainActivity](10231): Start draw after previous draw not visible
I: ImeTracker(10231): info.mqtt.android.extsample:5820dd82: onRequestHide at ORIGIN_CLIENT_HIDE_SOFT_INPUT reason HIDE_SOFT_INPUT
I: ImeTracker(10231): info.mqtt.android.extsample:5820dd82: onFailed at PHASE_CLIENT_VIEW_SERVED
D: AutofillManager(10231): view not autofillable - not passing ime action check

The very first issue: it's logged with V:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants