deptofdefense / AndroidTacticalAssaultKit-CIV

Other
918 stars 329 forks source link

Issue : Unable to start MQTT client service library using ATAK plugintemplate #104

Open kanagarajan0709 opened 3 years ago

kanagarajan0709 commented 3 years ago

Hi there,

[ATAK Civ source 4.3 & target android device samsung galaxy s8 ]

I have attempted to start the mqtt client service from onReceive() method in the PluginDropDownReceiver class. It throws run time exception and fails to establish the connection with broker server.

Failed to connect to: tcp://broker.hivemq.com:1883java.lang.RuntimeException: cannot start service org.eclipse.paho.android.service.MqttService

With the same client library code integrated using the example application from Android studio - it works.

I tried using both context mapView and pluginContext to start the Mqtt client service - both has the same problem.

Does the mapView context has the access to ATAK app manifest ?

Below are my changes to integrate paho mqtt client library,

plugin-examples/plugintemplate/app/build.gradle

image

image

image

I appreciate for any feedback related to this problem.

Thank you !

rob-baily commented 2 years ago

Hi @kanagarajan0709 I have also been looking at this and unable to make any progress as well. It seems there is some general problem using services in the plugin system. I tried using the NotificationService that is in the HelloWorld plugin and that does not work either. It does not seem to instantiate an instance of this class as I debugged and the onCreate() method is never called. I think I will submit an issue for that and we can see if there is anything there. It seems that it must be a fairly low level issue. It probably does not help that the way services are being created has changed in Android.

rob-baily commented 2 years ago

@kanagarajan0709 I got back to looking at this through research in #189 and you can check the notes. The gist of it is that there are 2 things that need to happen in this plugin for a service to be started locally that can be interacted with:

The MQTT package you are trying to use has also not been updated with any of the new interfaces to start foreground services and certainly has no AIDL. I looked a bit at https://github.com/hannesa2/paho.mqtt.android which has a more up to date implementation of the Android interface but it will also only work for a local service so it won't work with ATAK. What we have done instead is create a fork of https://github.com/pepzer/MQTTDroid which allows us to set up an MQTT service that can run in the background and provides an AIDL interface we use in our ATAK plugin. It is kind of convoluted but I don't think there is any other option right now.