首页 > 数据库技术 > 详细

sendBroadcast无法接收消息可能原因

时间:2018-12-23 10:30:53      阅读:337      评论:0      收藏:0      [点我收藏+]

Beginning with Android 8.0 (API level 26), the system imposes additional restrictions on manifest-declared receivers. If your app targets API level 26 or higher, you cannot use the manifest to declare a receiver for most implicit broadcasts (broadcasts that do not target your app specifically).

意思静态注册的广播在8.0以上是不能用,推荐用代码注册广播。
解决方案可以这么做:

配置:

<receiver android:name="MyStart">

    <intent-filter>
<action android:name="com.example.y.myapplication" />
</intent-filter>
</receiver>
代码:
Intent intent = new Intent();
                intent.setComponent(new ComponentName("com.example.y.myapplication","com.example.y.myapplication.MyStart"));
                getApplicationContext().sendBroadcast(intent);

sendBroadcast无法接收消息可能原因

原文:https://www.cnblogs.com/ylwn817/p/10163290.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!