//
//获取手机连接
ConnectivityManager manager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
//获取网络信息
NetworkInfo info = manager.getActiveNetworkInfo();
//判断
if(info ==null){
AlertDialog.Builder builder =newAlertDialog.Builder(MainActivity.this);
builder.setTitle("提示?");
builder.setMessage("是否跳转到设置");
builder.setPositiveButton("确定",newAlertDialog.OnClickListener() {
@Override
public voidonClick(DialogInterface dialogInterface,inti) {
startActivity(newIntent(android.provider.Settings.ACTION_WIFI_SETTINGS));
}
});
builder.setNegativeButton("取消",null);
AlertDialog dialog = builder.create();
dialog.show();
}else{
Toast.makeText(MainActivity.this,"连接成功?",Toast.LENGTH_SHORT).show();
}
}
网友评论