@Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   // TODO Auto-generated method stub
   //    Log.d(DEBUG_TAG, "requestCode" + requestCode + "=>" + "resultCode"
   //        + resultCode);
   super.onActivityResult(requestCode, resultCode, data);
   if (requestCode == REQUEST_ENABLE_BT) {
     if (resultCode == Activity.RESULT_OK) {
       // bluetooth is opened
       // select bluetooth device fome list
       Intent intent = new Intent(PortConfigurationActivity.this, BluetoothDeviceList.class);
       startActivityForResult(intent, REQUEST_CONNECT_DEVICE);
     } else {
       // bluetooth is not open
       Toast.makeText(this, R.string.bluetooth_is_not_enabled, Toast.LENGTH_SHORT).show();
     }
   } else if (requestCode == REQUEST_CONNECT_DEVICE) {
     // When DeviceListActivity returns with a device to connect
     if (resultCode == Activity.RESULT_OK) {
       // Get the device MAC address
       String address = data.getExtras().getString(EXTRA_DEVICE_ADDRESS);
       // fill in some parameters
       tvPortInfo.setVisibility(View.VISIBLE);
       tvPortInfo.setText(getString(R.string.bluetooth_address) + address);
       btConnect.setVisibility(View.VISIBLE);
       mPortParam.setBluetoothAddr(address);
     }
   } else if (requestCode == REQUEST_USB_DEVICE) {
     // When DeviceListActivity returns with a device to connect
     if (resultCode == Activity.RESULT_OK) {
       // Get the device MAC address
       String address = data.getExtras().getString(EXTRA_DEVICE_ADDRESS);
       // fill in some parameters
       tvPortInfo.setVisibility(View.VISIBLE);
       tvPortInfo.setText(getString(R.string.usb_address) + address);
       btConnect.setVisibility(View.VISIBLE);
       mPortParam.setUsbDeviceName(address);
     }
   }
 }
 public void okButtonClicked(View view) {
   String ipAddress = etIpAddress.getText().toString();
   String portNum = etPortNum.getText().toString();
   mPortParam.setIpAddr(ipAddress);
   mPortParam.setPortNumber(Integer.valueOf(portNum));
   Intent intent = new Intent(this, PrinterConnectDialog.class);
   Bundle bundle = new Bundle();
   bundle.putInt(GpPrintService.PORT_TYPE, mPortParam.getPortType());
   bundle.putString(GpPrintService.IP_ADDR, mPortParam.getIpAddr());
   bundle.putInt(GpPrintService.PORT_NUMBER, mPortParam.getPortNumber());
   bundle.putString(GpPrintService.BLUETOOT_ADDR, mPortParam.getBluetoothAddr());
   bundle.putString(GpPrintService.USB_DEVICE_NAME, mPortParam.getUsbDeviceName());
   intent.putExtras(bundle);
   this.setResult(Activity.RESULT_OK, intent);
   this.finish();
 }