无网络连接 弹出框无标题文章
2017-07-27 本文已影响0人
bbf7b8bde7af
//
//获取手机连接
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();
}
}