「以上13步骤需要开发者完成,45步骤由Android系统完成。」
「样例:」
4.1静态注册
- 4.1.1自定义广播接受者,继承BroadcastReceiver基类并重写onReceive()即可:
public class SCCReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.e(getClass().getName(),“SCCReceiver,传递内容:”+intent.getStringExtra(“scc”));
}
}
- 4
《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》
【docs.qq.com/doc/DSkNLaERkbnFoS0ZF】 完整内容开源分享
.1.2在AndroidManifest.xml中通过receive标签进行申明
<receiver
android:name=".SCCReceiver"
android:enabled=“true”
android:exported=“true”/>
-
4.1.3发送广播
-
activity_main.xml
<LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:gravity=“center_horizontal”
android:orientation=“vertical”>
<Button
android:id="@+id/btn_send"
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:text=“发送静态广播” />
- MainActivity.java
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.act