/BroadcastReceive

Tooling kit for debug application

Primary LanguageKotlin

Description

Tool for debug application. Allows you to update any value dynamically

How it work?

Based on BroadcastReceiver. Content is sent via adb. For your convenience, a script has already been written to send a broadcast message. You receive the message and extract the data.

How it use?

  1. Register BroadcastReceiver using extension function. See extension function list

Example

Code sample below show how to register reciver. It`s easy.

// You must provide Context, because onBroadcastReceiveString method is extension of Context
private fun debugReceivingName(context: Context) : Flow<String> {
  val debugFlow = MutableSharedFlow<String>(replay = 0, extraBufferCapacity = 1)
  // method will called with default arguments
  context.onBroadcastReceiveString { receivedString ->
    // react to received data
    sharedFlow.tryEmit(receivedString)
  }
  return debugFlow
  // collect and update your state in outside this method
}
  1. Send broadcast message with our script or adb command directly.
  • Using our script:
    ./sendString DEFAULT_ACTION DEFAULT_PAYLOAD "Hello World!"

Caution ⚠️

Don't use in production! This tool can be applied for debuging and developing android application. All extensions call registerBroadcastReceiver(), but not call unregisterBroadcastReceiver() method! Care about your users in production.

Setup

Today, you can add dependency of library only localy (clone and setup as local module). See sample

TODO:

  • Add lifecycle for unregistering receiver
  • Support multiple devices
  • Add ability send broadcast with multiple payloads
  • Add ability send json
  • Create plugin for IDE
  • Simplify script usage