title: Android Bluetooth Printing
body: <p>I am writing an application which sends data to bluetooth printer. Can anyone help me ? how can I use android Bluetooth Stack for printing? or is there any external api or sdk to use?</p>
  
  <p>Here is my code for searching bluetooth...</p>
  
  <pre><code>bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
  registerReceiver(ActionFoundReceiver,
          new IntentFilter(BluetoothDevice.ACTION_FOUND));
  
  private final BroadcastReceiver ActionFoundReceiver = new BroadcastReceiver() {
      @Override
      public void onReceive(Context context, Intent intent) {
          String action = intent.getAction();
          if (BluetoothDevice.ACTION_FOUND.equals(action)) {
              BluetoothDevice device = intent
                      .getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
              btArrayAdapter.add(device.getName() + "\n"
                      + device.getAddress());
              btArrayAdapter.notifyDataSetChanged();
          }
      }
  };
  </code></pre>
  
  <p>and here is my code for sending data to printer..</p>
  
  <pre><code>BluetoothDevice mDevice = bluetoothAdapter.getRemoteDevice("00:15:FF:F2:56:A4");
  Method m = mDevice.getClass().getMethod("createRfcommSocket",
          new Class[] { int.class });
  mBTsocket = (BluetoothSocket) m.invoke(mDevice, 1);
  System.out.println("Connecting.....");
  mBTsocket.connect();
  System.out.println("Connected");
  OutputStream os = mBTsocket.getOutputStream();
  os.flush();
  os.write(Receipt.getBytes());
  // mBTsocket.close();
  </code></pre>
  
  <p>When I write socket.close() , data is not getting print to printer as socket connection getting closed before printing data..and if I didn't write socket.close() then data is getting printed only once.. I would not be able to print data second time until I restart bluetooth of my phone.</p>
  
  <p>can any one have solution for it??? or is there any other way to get rid of this printing??</p>