Android Broadcast
SendレスポンスとReceiveトリガーでチャンネルとしてAndroid Broadcastsを選びAndroid Broadcast を使用することでプロトタイプを他のAndroid アプリと相互作業することができます。
Android アプリからプロトタイプにメッセージを送るには、 io.protopie.action.ONE_TIME_TRIGGERアクションとIntentを使用した送信します。
val intent = Intent("io.protopie.action.ONE_TIME_TRIGGER")
intent.putExtra("messageId", "YOUR_MESSAGE_ID")
intent.putExtra("value", "123") // Optional
context.sendBroadcast(intent)
io.protopie.action.ONE_TIME_RESPONSE アクション用にInterFilterを使用して BroadcastReceiverを登録します。
val receiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
val messageId = intent.getStringExtra("messageId")
val value = intent.getStringExtra("value")
println("Message from ProtoPie. messageId=$messageId value=$value")
}
}
val filter = IntentFilter("io.protopie.action.ONE_TIME_RESPONSE")
context.registerReceiver(receiver, filter)