想了解Android中监听系统网络连接打开或者关闭的实现代码的相关内容吗,在本文为您仔细讲解Android 监听的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:Android,监听,下面大家一起来学习吧。
public class NetstateReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
ConnectivityManager manager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo gprs = manager
.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
NetworkInfo wifi = manager
.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (!gprs.isConnected() && !wifi.isConnected()) {
// network closed
} else {
// network opend
}
}
}