接受信息并做出对应处理
注册方式:静态广播(app在非运行状态下接受系统通知)和动态广播(运行状态下组件间的通信)
AndroidManifest.xml静态注册
<receiver android:name=".broadcastreceiver.ConnectChangeReceiver">
<intent-filter>
<action android:name="android.net.com.CONNECTIVITY_CHANGE"/>
<intent-filter>
</receiver>
@Override
public void onReceive(Context context,Intent intent){
String action = intent.getAction();
if(action.equals(ConnectivityManager.CONNECTIVITY_ACTION){
Toast.makeText(this,"网络状态已改变“,Toast.LENGTH_SHORT).show();
}
}