어느 버전부터인가 이런 메시지와 함께 broadcast가 제대로 전달되지 않는다.
그래서 온라인상의 example들이 의도와 다르게 동작하지 않아 혈압 상승을 유발.
그럴 땐 intent에 아래와 같이 ComponentName을 생성하여 보내고자하는 broadcast intent에 달아주자.
ComponentName의 인자로는 class 객체를 넣어줘야 하는데 kotlin에서는 아래와 같은 방식으로 호출하면 된다.
"BroadcastQueue: Background execution not allowed: receiving Intent"
override fun onKeyUp(keyCode: Int, event: KeyEvent?): Boolean {
if ( keyCode == KeyEvent.KEYCODE_1){
Log.d("easy", "pressed keycode_1")
var i = Intent("a.b.c")
var comp = ComponentName(application, TestBroadCastReceiver::class.java)
i.setComponent(comp)
or
var comp = ComponentName(application, "com.test.testapplication.receiver.TestBroadCastReceiver")
i.setComponent(comp)
or
i.setPackage("com.test.testapplication")
or
다른 앱에서 실행 할 경우
var comp = ComponentName("com.test.testapplication","com.test.testapplication.receiver.TestBroadCastReceiver")
i.setComponent(comp)
i.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES)
* 삽질 후 알아냄 : 참고로 receiver는 TestBroadCastReceiver.java를 포함하는 경로이며 ComponentName의 package name에서는 제외한다.
sendBroadcast(i)}
return super.onKeyUp(keyCode, event)
}
'android' 카테고리의 다른 글
Android audio tutorial (link) (0) | 2019.08.27 |
---|---|
android service exported true의 의미. (0) | 2019.08.01 |
broadcast monitor (history 보기) (0) | 2019.07.15 |
No Jack server running. Try 'jack-admin start-server' 대처 (0) | 2019.07.03 |
gcc: execv returned (No such file or directory) (0) | 2019.07.03 |