与其它安卓App进行通信
当选择"发送"与"接收"的渠道属性为 Android Broadcasts时,可以通过安卓上安装的ProtoPie Player,让正在执行的原型与安卓设备上的其他APP通讯。
如需从其他App向ProtoPie Player发送消息,可通过创建以io.protopie.action.ONE_TIME_TRIGGER为action的Intent后以Broadcast形式发出。
val intent = Intent("io.protopie.action.ONE_TIME_TRIGGER")
intent.putExtra("messageId", "YOUR_MESSAGE_ID")
intent.putExtra("value", "123") // Optional
context.sendBroadcast(intent)
如需从ProtoPie Player向App发送信息,可以创建BroadcastReceiver来接收带有action值 io.protopie.action.ONE_TIME_RESPONSE 的Broadcast。
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)