public class ConnectionBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if (!NetUtil.isNetworkAvalibleService(context)) {
Toast.makeText(context,
"您的网络已经断开,请检查网络!", Toast.LENGTH_LONG)
.show();
}else{
Toast.makeText(context,
"您的网络已经连接!", Toast.LENGTH_LONG)
.show();
}
}
}
<pre name="code" class="html"> <receiver android:name="com.receiver.ConnectionBroadcastReceiver"
>
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>