admin管理员组文章数量:1405990
I have created my own BroadcastReceiver like so:
class BogusBroadcastReceiver: BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
if(intent?.action == ACTION_NAME){
Log.d { "Received Broadcast!!" }
}
}
private companion object {
const val ACTION_NAME = "com.myapp.intent.BOGUS_ACTION"
}
}
And i declare it in my manifest like this:
<application
android:name=".MyApp"
android:banner="@mipmap/ic_banner"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name">
<receiver android:name=".test.BogusBroadcastReceiver" android:exported="true" android:enabled="true">
<intent-filter>
<action android:name="com.myapp.intent.BOGUS_ACTION" />
</intent-filter>
</receiver>
...
</application>
However when i try to trigger it from adb like:
adb shell am broadcast -a com.myapp.intent.BOGUS_ACTION
I get:
Broadcasting: Intent { act=com.myapp.intent.BOGUS_ACTION flg=0x400000 }
Broadcast completed: result=0
But the log line never gets printed and my BroadcastReceiver doesnt run, regardless of the app being in foreground or background.
What am i missing here?
本文标签: androidCreating custom BroadcastReceiver with custom actionStack Overflow
版权声明:本文标题:android - Creating custom BroadcastReceiver with custom action - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744969432a2635144.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论