apidocs / com.nimmsta.core.android.framework / NIMMSTAServiceConnection

NIMMSTAServiceConnection

open class NIMMSTAServiceConnection : ServiceConnection

This class provides access to the NIMMSTAConnectionManager and initiates the connection. It uses an Android ServiceConnection and the concept of background Tasks. Just register the NIMMSTAServiceConnection by calling bindServiceToActivity and register for completion for the binding with onComplete. Only then you're able to do calls like displayConnectionActivity in order to show the DeviceConnectActivity. You can also check for ready with the isReady property. The following example shows a simple implementattion of this:

    private lateinit serviceConnection: NIMMSTAServiceConnection

    protected fun initConnection() {
        serviceConnection = NIMMSTAServiceConnection.bindServiceToActivity(this).onComplete {
            try {
                it.result

                if(!it.isConnected) {
                    it.displayConnectionActivity()
                }
            } catch(t: Throwable) {
                // handle error
            }
        }
    }

    // prevent Memory-Leaking
    protected fun onDestroy() {
        serviceConnection.close()
    }

If you want to have notifications by the NIMMSTADevice just add NIMMSTADeviceDelegate to your activity or pass a delegate class as second parameter. You can always set a new delegate afterwards by setting the delegate of the object you received.

Author
NIMMSTA Team

Copyright
NIMMSTA GmbH & IBPG 2020

License
NIMMSTA GmbH

Properties

connectedDevices

Provides access to all connected devices.

val connectedDevices: Set<NIMMSTADevice>?

connectionManager

reference to the NIMMSTAConnectionManager, based on INIMMSTAConnectionManager. Will be set once service was connected.

val connectionManager: NIMMSTAConnectionManager?

connectionStrategy

The connection strategy defines how new devices get connected. See IConnectionStrategy.Companion for some default strategies.

val connectionStrategy: IConnectionStrategy

delegate

this is the delegate of NIMMSTADevice. Set it to an object in order to register for events. You can also just inherit NIMMSTADeviceDelegate on your Activity/Service binding to and it is managed automatically.

var delegate: NIMMSTAEventHandler?

devices

Provides access to devices.

val devices: DeviceList?

hasActiveConnections

Returns if any connections are active.

val hasActiveConnections: Boolean

isReady

returns true if service connection exists.

val isReady: Boolean

Functions

await

awaits resukt

suspend fun await(): NIMMSTAServiceConnection

close

close the service.

fun close(): Unit

displayConnectionActivity

Displays the DeviceConnectActivity. This is only possible once the service NIMMSTAConnectionManager is referenced. You can find out by checking isReady attribute or setting a callback to onComplete or onSuccess.

fun displayConnectionActivity(): Unit

enableBackgroundAndNotifications

Enables notifications for connected / disconnected scanner. This also enables background ability, so that if the phone goes into standby, it still talks to the HS 50 in the background.

fun enableBackgroundAndNotifications(): Unit

onComplete

Lambda is called once service was connected or thrown an error. Returns ServiceConnection.

fun onComplete(lambda: (Task<NIMMSTAServiceConnection>) -> Unit): NIMMSTAServiceConnection

DoneCallback is called once service was connected or thrown an error. Returns ServiceConnection.

fun onComplete(lambda: NIMMSTADoneCallback<Task<NIMMSTAServiceConnection>>): NIMMSTAServiceConnection

onError

Lambda is called once error was thrown. Returns ServiceConnection.

fun onError(lambda: (Throwable) -> Unit): NIMMSTAServiceConnection

FailCallback is called once error was thrown. Returns ServiceConnection.

fun onError(lambda: NIMMSTAFailCallback<Throwable>): NIMMSTAServiceConnection

onServiceConnected

open fun onServiceConnected(p0: ComponentName?, binder: IBinder?): Unit

onServiceDisconnected

open fun onServiceDisconnected(p0: ComponentName?): Unit

onSuccess

Lambda is called once service was connected and is ready. Won't be called once error was thrown. Returns ServiceConnection.

fun onSuccess(lambda: (NIMMSTAServiceConnection) -> Unit): NIMMSTAServiceConnection

DoneCallback is called once service was connected and is ready. Won't be called once error was thrown. Returns ServiceConnection.

fun onSuccess(lambda: NIMMSTADoneCallback<NIMMSTAServiceConnection>): NIMMSTAServiceConnection

setConnectionStrategy

sets a given connection strategy. Please be aware this is an async method and will only update after completion.

fun setConnectionStrategy(strategy: IConnectionStrategy): Task<Unit>

Companion Object Functions

bindServiceToActivity

Binds the NIMMSTA Service to an activity, fragment or Android Service. If context implements NIMMSTADeviceDelegate, it will automatically be registered as listener. If you want to set a custom delegate, provide is as second parameter.

fun bindServiceToActivity(context: Context, delegate: NIMMSTAEventHandler? = null): NIMMSTAServiceConnection