android activity pass data to accessibilityservice 数据传递

不同类型的 service 传递数据的方式不同,accessibilityservice 运行在独立进程,且被系统接管,比较特别

在 AccessibilityService 的 onCreate 内加一个 BroadcastReceiver

val broadcast = object:BroadcastReceiver(){
        override fun onReceive(context: Context?, intent: Intent?) {
            val what = intent?.getStringExtra("hello",  "dlrow")!!
        }
}
registerReceiver(broadcast, IntentFilter("hangj.cnblogs.com"))

onUnbind 里

unregisterReceiver(broadcast)

在 Activity 内 sendBroadcast

sendBroadcast(Intent().apply {
    action="hangj.cnblogs.com"
    putExtra("hello", "world")
})

还可以用 socket

posted on 2020-09-28 13:04  明天有风吹  阅读(595)  评论(0编辑  收藏  举报

导航

+V atob('d2h5X251bGw=')

请备注:from博客园