Installed App Webservice Connection
Use NIMMSTAWebServiceConnection when your Android app should bind to the WebService of an installed NIMMSTA app on the same device.
This is useful when:
- your app wants local Web Library or Websocket access without embedding the Core Android webservice itself
- you already use the Intent Library and want the same installed-app package resolution for the webservice
- you want one helper that supports Standard App, Intent App, Webserver App, and an optional preferred custom package
Resolution Order
NIMMSTAWebServiceConnection.bindServiceToContext(...) tries these packages in order:
- Preferred custom package, if configured
- Standard App:
com.nimmsta - Intent App:
com.nimmsta.intent - Webserver App: current builds also use
com.nimmsta
You can configure the preferred package once through NIMMSTAService.preferredPackageName.
Manifest Notes
The Intent Library manifest already queries com.nimmsta and com.nimmsta.intent. Current Webserver App builds also use com.nimmsta.
If you use a custom package, add it to your app manifest as well:
Basic Usage
class MainActivity : AppCompatActivity() {
private var webServiceConnection: NIMMSTAWebServiceConnection? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
webServiceConnection = NIMMSTAWebServiceConnection
.bindServiceToContext(applicationContext)
.onSuccess { connection ->
// connected to the installed app's WebService
}
.onError { throwable ->
Toast.makeText(this, throwable.message, Toast.LENGTH_LONG).show()
}
}
override fun onDestroy() {
webServiceConnection?.close()
super.onDestroy()
}
}
public class MainActivity extends AppCompatActivity {
private NIMMSTAWebServiceConnection webServiceConnection;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
webServiceConnection = NIMMSTAWebServiceConnection
.bindServiceToContext(getApplicationContext())
.onSuccess(connection -> {
// connected to the installed app's WebService
})
.onError(throwable -> {
Toast.makeText(this, throwable.getMessage(), Toast.LENGTH_LONG).show();
});
}
@Override
protected void onDestroy() {
if (webServiceConnection != null) {
webServiceConnection.close();
}
super.onDestroy();
}
}
Inspect the Connected Target
If you need to know which installed app was selected, inspect connectedCandidate.
webServiceConnection = NIMMSTAWebServiceConnection
.bindServiceToContext(getApplicationContext())
.onSuccess(connection -> {
String packageName = connection.getConnectedCandidate() != null
? connection.getConnectedCandidate().getPackageName()
: null;
NIMMSTAInstalledAppType appType = connection.getConnectedCandidate() != null
? connection.getConnectedCandidate().getAppType()
: null;
});