总结
1、设置广播:设置自定义广播:
Intent intent=new Intent();
intent.setAction(Constants.ACTION_SEND_MSG);
2、发送广播:sendBroadcast(intent);
3、接收广播:创建广播接收者
4、注册广播:静态注册/动态注册
5、控制台打印出相关信息进行效果验证(可舍)
————————————————————————
————————————————————————
前期准备工作:
自定义一个button并设置onclick属性,自定义一个editText用来编辑广播内容:
<EditText
android:id="@+id/et_message_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入……"/>
<Button
android:onClick="sendBroadcastMsg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="发送通知"/>
一、发送广播
1、写onclick属性中的方法(即点击button的时候会自动调用该方法,即点击button的时候就会发送广