Android 开发问题:notificationReceiver is missing RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED flag
registerReceiver(notificationReceiver,intentFilter);在 Android 开发中上述代码出现如下错误信息notificationReceiver is missing RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED flag for unprotected broadcasts registered for NOTIFICATION_ACTIONIn Android U, all receivers registering for non-system broadcasts are required to include a flag indicating the receivers exported state. Apps registering for non-system broadcasts should use the ContextCompat#registerReceiver APIs with flags set to either RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED.# 解读 notificationReceiver广播接收器缺少 RECEIVER_EXPORTED 或 RECEIVER_NOT_EXPORTED 标志该接收器注册了未受保护的 NOTIFICATION_ACTION 广播。# 解读 在 Android U 中所有注册非系统广播的接收器都必须包含一个标志用于指明接收器的导出状态。 应用注册非系统广播时应当使用 ContextCompat#registerReceiver API并将标志设置为 RECEIVER_EXPORTED 或 RECEIVER_NOT_EXPORTED。问题原因注册的广播接收器 notificationReceiver 监听的是NOTIFICATION_ACTION广播接收器未声明导出标志标志说明RECEIVER_EXPORTED允许其他应用发送广播RECEIVER_NOT_EXPORTED仅限本应用接收处理策略添加导出标志registerReceiver(notificationReceiver, intentFilter, RECEIVER_NOT_EXPORTED);但是之后又出现如下警告信息带标志的 registerReceiver 方法 Android 8.0API 26引入的但应用 minSdkVersion 设置为 24Call requires API level 26 (current min is 24): android.content.ContextWrapper#registerReceiver# 解读 调用要求 API 级别 26当前最低支持级别是 24android.content.ContextWrapper#registerReceiver使用 ContextCompat 做兼容处理ContextCompat.registerReceiver(this, notificationReceiver, intentFilter, ContextCompat.RECEIVER_NOT_EXPORTED);