ConnectivityManager cm = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo nwi = cm.getActiveNetworkInfo();
if(nwi!=null){
return nwi.isAvailable();
}
return false;
}
/**
* 提示是否打开网络连接的对话框
*/
@Override
protected Dialog onCreateDialog(int id) {
if(id == WIRELESS_SETTING){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("网络连接提示");
builder.setMessage("当前没有可用网络,是否设置?")
.setCancelable(false)
.setPositiveButton("设置", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Intent intent = new Intent(Settings.ACTION_WIRELESS_SETTINGS);
startActivity(intent);
}
})
.setNegativeButton("退出", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
finish();
}
});
return builder.create();
}
return null;
}