ConnectivityManager cManager = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = cManager.getActiveNetworkInfo();
if (info == null || !info.isAvailable()) {
TextView dialog = new TextView(this);
dialog.setText(R.string.currentNetFaild);//R中的string都是在string.xml中自定義的 可以自己修改
new AlertDialog.Builder(this).setTitle(
getResources().getString(R.string.dialogTitle)).setView(dialog)
.setPositiveButton(getResources().getString(R.string.ok),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
startActivityForResult(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS), 0);//設(shè)置完畢會(huì)返回當(dāng)前應(yīng)用
}
}).create().show();
}
聯(lián)系客服