Getting Started
The intent library communicates with the NIMMSTA Android App by using Android intents.
Requirements
- NIMMSTA Android App Version 6.0 or above
- If you use NIMMSTA App 7.0.5 or older: Make sure NIMMSTA App is installed before your app, otherwise the permissions are not set correctly.
Maven Repository
Next add the NIMMSTA Maven Repository to the settings.
Integrate Intent Library
To get started with the NIMMSTA Intent Library, you have to add the library as a dependency to your Android Project and have access to the NIMMSTA Maven Repo.
Initialize library (Activity Option)
To initialize the communication between your app and the NIMMSTA App you have to bind to NIMMSTAIntentConnection. You can also use Option 2, where the connection is bound to the application and always close automatically when your app goes to background.
// optional: adapt Package name when using your own package name:
NIMMSTAService.serviceName = ComponentName("com.nimmsta.custom", "com.nimmsta.core.android.intents.NIMMSTAIntentService")
NIMMSTAIntentConnection.Companion.bindServiceToActivity(this).onComplete((task) -> {
NIMMSTAIntentConnection connection = task.getResult();
NIMMSTAManager manager = connection.getManager();
return null;
});
Remember to cancel all connection attempts and to close the connection to the NIMMSTA App. You can do this in the onDestroy method of an activity for example
Initialize library (Application Option)
This option is great if you want to keep the connection to the NIMMSTA App alive while your app is in the foreground, but
automatically close it when your app goes to the background. Attention: It will have a delay of 1 seconds by default
when your app goes to the background before the connection is closed. You can change this delay by setting the ApplicationIntentConnection.disconnectDelay.
You can bind the connection to the application context in your Application class.
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
ApplicationIntentConnection.startObserving(this)
}
}
/**
* Activity
*/
class MyActivity : AppCompatActivity() {
private lateinit var manager: NIMMSTAManager
override fun onResume() {
super.onResume()
// get Manager when connection is ready
ApplicationIntentConnection.onReady { manager ->
// called once when connection is ready
}
// Access current manager (maybe null)
ApplicationIntentConnection.manager?.let { manager ->
// may never be called
}
}
}
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
ApplicationIntentConnection.Companion.startObserving(this);
}
}
/**
* Activity
*/
public class MyActivity extends AppCompatActivity {
@Override
protected void onResume() {
super.onResume();
// get Manager when connection is ready
ApplicationIntentConnection.Companion.onReady((manager) -> {
// called once when connection is ready
return null;
});
// Access current manager (maybe null)
NIMMSTAManager currentManager = ApplicationIntentConnection.Companion.getManager();
if (currentManager != null) {
// may never be called
}
}
}
Next Steps
To learn more about what you can do with the NimmstaManager or the NimmstaDevice head to the dedicated pages for them.