android 广播机制如何深入? android系统中的广播机制有没有系统广播,分别都是那些?android 广播 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 楼上的朋友,android系统中有很多自带的广播机制,当然android平台上还可以自定义。比如我们常用的一个网络信号监控问题,当你断网时,你可以自定义service去反复监测,不过这就不如系统广播来的快,并且还有保障。贴点代码给你。 public class extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { State wifiState = null; State mobileState = null; ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); wifiState = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState(); mobileState = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState(); if (wifiState != null && mobileState != null && State.CONNECTED != wifiState && State.CONNECTED == mobileState) { // 手机网络连接成功 } else if (wifiState != null && mobileState != null && State.CONNECTED != wifiState && State.CONNECTED != mobileState) { // 手机没有任何的网络 } else if (wifiState != null && State.CONNECTED == wifiState) { // 无线网络连接成功 } } ListView动态适应内容长度 java中引用System.loadLibrary的疑问 eclipse-rcp-ganymede-3.4终于下载到了,但是编译出现个问题 android 开发现在工资高吗?有前途吗?我是做web开发,想转android开发 GPS数据不实时更新问题!!! android上的中文tts语音功能 安卓的apk播放本地视频安装在智能电视上播放不了 求个demo android jar包问题 #移动开发 Spinner的样式应该如何设置 一个应用是否可以有2个入口activity?
public class extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
State wifiState = null;
State mobileState = null;
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
wifiState = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
mobileState = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState();
if (wifiState != null && mobileState != null
&& State.CONNECTED != wifiState
&& State.CONNECTED == mobileState) {
// 手机网络连接成功
} else if (wifiState != null && mobileState != null
&& State.CONNECTED != wifiState
&& State.CONNECTED != mobileState) {
// 手机没有任何的网络
} else if (wifiState != null && State.CONNECTED == wifiState) {
// 无线网络连接成功
}
}