App启动时候使用BroadcastReceiver监听网络情况,不能保证所有设备能监听到

来源:互联网 发布:淘宝上卖面膜 许可证 编辑:程序博客网 时间:2024/06/14 02:44
public class ConnectionBroadcastReceiver extends BroadcastReceiver {@Overridepublic void onReceive(Context context, Intent intent) {// TODO Auto-generated method stubif (!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>



0 0
原创粉丝点击