当需要开启Activity之前需要检测网络状态的时候需要用到一下代码。最近也在做DataConn方面的内容,分享下了...
private boolean NetWorkStatus() {
boolean netSataus = false;
ConnectivityManager cwjManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
cwjManager.getActiveNetworkInfo();
if (cwjManager.getActiveNetworkInfo() != null) {
netSataus = cwjManager.getActiveNetworkInfo().isAvailable();
}
if (!netSataus){
Builder b = new AlertDialog.Builder(this).setTitle("没有可用的网络").setMessage("是否对网络进行设置?");
b.setPositiveButton("是", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Intent mIntent = new Intent("/");
ComponentName comp = new ComponentName("com.android.settings", "com.android.settings.WirelessSettings");
mIntent.setComponent(comp);
mIntent.setAction("android.intent.action.VIEW");
startActivityForResult(mIntent,0); // 如果在设置完成后需要再次进行操作,可以重写操作代码,在这里不再重写
}
}).setNeutralButton("否", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.cancel();
}
}).show();
}
return netSataus;
}
分享到:
相关推荐
Android 判断当前网络是否可用简单实例 用户手机当前网络可用:WIFI、2G/3G网络,用户打开与不打开网络,和是否可以用是两码事。可以使用指的是:用户打开网络了并且可以连上互联网进行上网。 首页添加网络权限 ...
仿QQ微信,Android开发中网络连接状态的判断(判断android设备是否有网络),详细了解请移步http://blog.csdn.net/zxc514257857/article/details/69219113
android 判断网络状态
判断Android客户端网络连接状态ConnectivityManager cm = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); boolean ...
android判断网络状态、获取网络运营商、网络类型的工具类,并提供打开网络设置界面接口
在使用Android连接网络的时候,...要判断网络状态,首先需要有相应的权限,下面为权限代码: 即允许访问网络状态: <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"> 下面为判断代码:
Android系列之如何判断网络链接状态
android判断网络的状态断开与否.android判断网络的状态断开与否
android判断网络连接状态,以及网络连接类型
Android网络状态判断
Android开发中网络连接状态的判断(判断android设备是否有网络),详细了解请移步http://blog.csdn.net/zxc514257857/article/details/68066192
android 腾讯定位并判断网络连接 ,通过网络定位,在定位前先判断网络链接状态,状态良好,则定位。
android网络监听变化,判断当前是什么网络类型,实时监听。android网络监听变化,判断当前是什么网络类型,实时监听。android网络监听变化,判断当前是什么网络类型,实时监听。android网络监听变化,判断当前是什么...
Android应用网络状态判断
判断是否有网络连接,Android开发之java代码工具类,判断网络状态的工具类。
判断网络状态的工具类
Android移动开发检测网络状态并使用BroadcastReceiver(广播接收者)进行接收网络变化的后续处理
Android开发中网络连接状态的判断(判断android设备是否有网络),详细了解请移步: http://blog.csdn.net/zxc514257857/article/details/68066192
Android 判断网络状态及开启网路 在使用Android连接网络的时候,并不是每次都能连接到网络,在这个时候,我们最好是在程序启动的时候对网络的状态进行一下判断,如果没有网络则进行即时提醒用户进行设置。 要判断...
cordova 3.4 版本的API 判断网络的连接状态 调用phonegap API 判断网络类型 :2G 3G 4G wifi 等等 博客: http://blog.csdn.net/aaawqqq/article/details/22220319