Bullitt Android SDK
The Bullitt Android SDK provides functionality for satellite device discovery, pairing, and communication. This guide demonstrates how to integrate the SDK into your Android application.
Installation
Add the dependency to your app's settings.gradle:
repositories {
...
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/bullitt-mobile/bullitt_android_sdk")
credentials {
username = <your github username>
password = <your github token>
}
}
}Add the dependency to your app's build.gradle:
dependencies {
implementation "com.bullitt.sdk:bullitt_sdk_platform:2.0.0"
}Initialization
Initialize the SDK in your Application class:
class YourApplication : Application() {
override fun onCreate() {
super.onCreate()
BullittSDK.initialize(this) { globalEvent ->
// Handle global events from the SDK
handleGlobalEvents(globalEvent)
}
}
private suspend fun handleGlobalEvents(globalEvent: GlobalEvent) {
// Process global events (device status changes, messages, etc.)
}
}Core Features
1. Configuration
Before using the SDK, configure it with user-specific settings:
bullittApis.setConfig(
BullittConfig(
userId = userId, // User Phone Number
checkInNumber = number, // Check-in phone number
)
)2. Device Discovery
Scan for available satellite devices:
// Start scanning with 10-second timeout
bullittApis.listDevices(timeoutInMillis = 10000)
.collect { response ->
when (response) {
is StreamResponse.Data -> {
// Handle discovered device
when (response.data) {
is DeviceScanResult.Ble -> // Handle BLE device
is DeviceScanResult.D2d -> // Handle D2D device
}
}
is StreamResponse.End -> // Scanning completed
is StreamResponse.Failure -> // Handle error
}
}3. Device Pairing
// Request pairing with discovered device
val pairingResponse = bullittApis.requestDevicePairing(deviceScanResult)
if (pairingResponse is Response.Success) {
// Validate IMSI returned in pairingResponse.data.imsi. If valid, confirm device linking
val linkingResponse = bullittApis.confirmDeviceLinking()
if (linkingResponse is Response.Success) {
// Device successfully paired
}
}4. Device Management
Get currently linked device:
when (val response = bullittApis.getLinkedDevice()) {
is Response.Success -> {
val device = response.data
// Work with connected device
}
is Response.Failure -> {
// Handle no linked device
}
}Remove linked device:
bullittApis.removeLinkedDevice()5. Device Communication
Send messages to connected device:
// Create and send content
val content = TextContent(
controlFlag = SmpRequest.Content.ControlFlag.DELIVERY_RECEIPT_REQUIRED,
partnerId = 11234567890,
textMessage = "Hey Bullitt!",
)
linkedDeviceConnection.sendMessage(
linkedDeviceConnection.createContentBundle(content)
)6. Device Status Monitoring
Monitor device status through global events:
bullittApis.globalEvents.collect { event ->
when (event) {
is GlobalEvent.DeviceLinked -> // Device connected
is GlobalEvent.DeviceUnlinked -> // Device disconnected
is GlobalEvent.DeviceUpdate -> // Status update
is GlobalEvent.Message -> // New message received
}
}Permissions
Add required permissions to your AndroidManifest.xml:
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />Error Handling
The SDK uses a Response type for operation results:
Response.Success: Operation completed successfullyResponse.Failure: Operation failed with an exception
For streaming operations, StreamResponse is used:
StreamResponse.Data: New data availableStreamResponse.End: Stream completedStreamResponse.Failure: Stream error occurred
Best Practices
Always check if the SDK is initialized before accessing APIs
Handle permission requirements before scanning for devices
Implement proper error handling for all SDK operations
Monitor device status through global events for real-time updates
Sample Implementation
See the Demo app implementation for a complete example of SDK integration and usage patterns.