5.4 (Optional) Webservice Option
This section outlines optional configurations for integrating your Android application with the NIMMSTA webservice. This is needed if your app wants to use Web Library or Websocket library and wants to enable silent deployment.
There is two approaches: 1. Binding the Webservice of an installed NIMMSTA App (Recommended Way) 2. Integrate Core Library and bind Webserver locally
Binding the Webservice to the installed NIMMSTA App (NIMMSTA App Installation required - Recommended Way)
The recommended way is binding a locally installed NIMMSTA App's Webservice. Using this approach, updating the NIMMSTA App allows to get new features and improvements without updating your integration. Follow the instructions below to set up this connection:
- Update your AndroidManifest.xml: Add the following lines to your
AndroidManifest.xml
file to declare the necessary permissions and queries for the NIMMSTA app and webservice:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<!-- ... -->
<queries>
<package android:name="com.nimmsta" />
<package android:name="com.nimmsta.core.android.webservice.WebService" />
</queries>
<application>
<!-- Your application's components here -->
</application>
</manifest>
- Bind the service to your activity: To maintain a continuous connection, you must bind the webservice to your activity. This process is similar to the first approach but involves creating a service connection object. The implementation differs slightly between Kotlin and Java:
Define a WebServerServiceConnection
object with methods for handling connection and disconnection events:
import android.content.ComponentName
import android.content.ServiceConnection
import android.os.IBinder
object WebServerServiceConnection : ServiceConnection {
var binder: IBinder? = null
override fun onServiceConnected(p0: ComponentName?, p1: IBinder?) {
binder = p1
}
override fun onServiceDisconnected(p0: ComponentName?) {
// Handle disconnection
}
}
import android.content.ComponentName;
import android.content.ServiceConnection;
import android.os.IBinder;
public class WebServerServiceConnection implements ServiceConnection {
private IBinder binder;
private WebServiceConnectionDelegate delegate;
@Override
public void onServiceConnected(ComponentName p0, IBinder p1) {
binder = p1;
delegate.onConnect();
}
@Override
public void onServiceDisconnected(ComponentName p0) {
delegate.onDisconnect();
}
}
- Bind the service to your activity: After defining the
WebServerServiceConnection
object, bind the service to your activity using the following code snippet:
```kotlin val intent = Intent().apply { component = ComponentName("com.nimmsta", "com.nimmsta.core.android.webservice.WebService") flags += Intent.FLAG_INCLUDE_STOPPED_PACKAGES
} if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { context.bindService(intent, WebServerServiceConnection, Context.BIND_ALLOW_ACTIVITY_STARTS or Context.BIND_AUTO_CREATE) } else { context.bindService(intent, WebServerServiceConnection, Context.BIND_AUTO_CREATE) } ```
```java Intent intent = new Intent(); intent.setComponent(new ComponentName("com.nimmsta", "com.nimmsta.core.android.webservice.WebService")); intent.setFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { bindService(intent, WebServerServiceConnection, Context.BIND_ALLOW_ACTIVITY_STARTS | Context.BIND_AUTO_CREATE);
} else { bindService(intent, WebServerServiceConnection, Context.BIND_AUTO_CREATE); } ```
This code snippet binds the NIMMSTA webservice to your activity, ensuring that the webservice is available throughout the lifecycle of the activity.
Starting Webserver in your App (Core Library Integration required - First Approach)
This approach involves integrating the NIMMSTA webservice directly into your application using the SDK. Follow the steps below according to your programming language preference (Kotlin or Java).
- Import the NIMMSTA WebServiceConnection class in your file where you want to establish the connection:
- Bind the service to your activity by adding the following code snippet to your activity:
NIMMSTAWebServiceConnection serviceConnection = NIMMSTAWebServiceConnection.bindServiceToContext(getApplicationContext());
This line of code binds the NIMMSTA WebService to your activity, ensuring that the webservice is available throughout the lifecycle of the activity.