/aina-android

An Android library for Aina PTT accessories, written in Kotlin.

Primary LanguageKotlin

aina-android

Use Aina's PTT Voice Responder in your Android app.

User Guide

Installation

Add the library to your build.gradle:

repositories {
    jcenter()
}

dependencies {
  implementation 'com.masterjefferson:aina-ptt:0.0.2'
}

Permissions

Bluetooth permission is required:

<uses-permission android:name="android.permission.BLUETOOTH" />

Monitoring the connection state

import io.reactivex.Observable
import io.reactivex.disposables.Disposable
import com.masterjefferson.aina.ptt.android.AndroidAinaManager
import com.masterjefferson.aina.ptt.domain.model.AinaButton


private val ainaManager by lazy { AndroidAinaManager(this) }

fun monitorAinaConnection() {
  val disposable = ainaManager.connectedObservable
        .subscribe(
            { connected -> Log.i(TAG, "voice responder ${if (connected) "connected" else "disconnected"}") },
            { err -> Log.e(TAG, "error thrown by aina connection observable: $err") }
        )
}

You can also use AinaAccessoryManager.connected to quickly check if the accessory is connected.

Consuming button presses

import io.reactivex.Observable
import io.reactivex.disposables.Disposable
import com.masterjefferson.aina.ptt.android.AndroidAinaManager
import com.masterjefferson.aina.ptt.domain.model.AinaButton



private val ainaManager by lazy { AndroidAinaManager(this) }

fun consumeAinaButtonEvents() {
  val disposable = ainaManager.buttonEventsObservable
        .subscribe(
            { event -> Log.i(TAG, "${event.which} is ${if (event.pressed) "PRESSED" else "RELEASED"}") },
            { err -> Log.e(TAG, "error thrown by aina buttons: $err") }
        )
}