Android第一行代码第二版:5.3.2发送有序广播,在安卓8上无法接收广播我个人的处理方法

希望有大佬能教我别的方法,我明前只能想到这个方法啦。多谢!

书上的源代码是

Intent intent = new Intent("com.example.weiru.broadcasttest.MY_BROADCAST") ;

sendOrderedBroadcast(intent,null);

但是这样在安卓8上面行不通,我在前一篇博文已经处理过了,如下

Intent intent = new Intent("com.example.weiru.broadcasttest.MY_BROADCAST") ;
intent.setComponent(new ComponentName("com.example.weiru.broadcasttest",
        "com.example.weiru.broadcasttest.MyBroadcastReceiver")) ;
sendOrderedBroadcast(intent,null);

我以为这样就可以在别的APP里接收这个广播了,结果是错的。用安卓7就可以实现了。但是安卓8实现不了。经过了好久的脑力挣扎。最终弄出来如下的代码:

Intent intent = new Intent("com.example.weiru.broadcasttest.MY_BROADCAST") ;
Intent intent2 = new Intent("com.example.weiru.broadcasttest.MY_BROADCAST") ;
intent.setComponent(new ComponentName("com.example.weiru.broadcasttest",
          "com.example.weiru.broadcasttest.MyBroadcastReceiver")) ;
intent2.setComponent(new ComponentName("com.example.weiru.boradcasttest2",
          "com.example.weiru.boradcasttest2.AnotherBroadcastReceiver")) ;
sendOrderedBroadcast(intent,null);
sendOrderedBroadcast(intent2,null);

这样子就可以让另一个APP也收到广播啦。开心!

根据引用\[1\],问题中提到的错误是"Cannot resolve org.springframework.security:spring-security-config:5.3.2.RELEASE"。这个错误通常表示在项目的pom文件中找不到所需的Spring Security依赖。根据引用\[1\]中的pom文件片段,可以看到项目中已经添加了spring-boot-starter-security依赖,但是可能缺少了spring-security-config依赖。 解决这个问题的方法是在项目的pom文件中添加spring-security-config依赖。可以在<dependencies>标签中添加以下代码: ```xml <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-config</artifactId> <version>5.3.2.RELEASE</version> </dependency> ``` 这样就可以解决"Cannot resolve org.springframework.security:spring-security-config:5.3.2.RELEASE"的错误了。 #### 引用[.reference_title] - *1* *3* [微服务A读配置中心报Could not locate PropertySource错误](https://blog.csdn.net/weixin_53802962/article/details/113811491)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [springcloud框架搭建遇见的问题及解决办法](https://blog.csdn.net/m0_37546844/article/details/109525353)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值