学习笔记:弹出确认对话框并设置网络连接

public void btnSettingClick(View view) {
    	Toast.makeText(getBaseContext(), "clicked!", Toast.LENGTH_SHORT).show();
    	AlertDialog.Builder dialog = new AlertDialog.Builder(MainActivity.this);
    	dialog.setTitle("提示信息").setMessage("确认打开设置对话框?");
    	dialog.setPositiveButton("确定", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int which) {
				Intent i = null ;
				if(android.os.Build.VERSION.SDK_INT>10) {
					i = new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS);
				}else{
					i = new Intent();
					ComponentName name = new ComponentName("com.android.settings","com.android.settings.WirelessSettings");
					i.setComponent(name);
					i.setAction("android.intent.action.VIEW");
				}
				//Intent i = new Intent(android.settings.WIRELESS_SETTINGS);
				startActivity(i);
			}
		});
    	
    	dialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int which) {
			}
		}).show();
    }


你可能感兴趣的:(学习笔记:弹出确认对话框并设置网络连接)