title: Bluetooth Connection : Evolute Impress Printer not printing data
body: <p>I have an issue of connecting bluetooth device through mobile and i can able to send bytes as Outputstream but i cant able to retrive print from Evolute impress printer.Please help me how to get the print</p>
  
  <p><strong>Problem:</strong></p>
  
  <pre><code> how to check evolute printer whether its reciving data which i sent.
  </code></pre>
  
  <p><strong>Main.java</strong></p>
  
  <pre><code>public class Main extends Activity implements Runnable {
              protected static final String TAG = "TAG";
              private static final int REQUEST_CONNECT_DEVICE = 1;
              private static final int REQUEST_ENABLE_BT = 2;
              Button mScan, mPrint, mDisc,check;
              BluetoothAdapter mBluetoothAdapter;
              private UUID applicationUUID = UUID
                      .fromString("00001101-0000-1000-8000-00805F9B34FB");
              private ProgressDialog mBluetoothConnectProgressDialog;
              private BluetoothSocket mBluetoothSocket;
              BluetoothDevice mBluetoothDevice;
  
              @Override
              public void onCreate(Bundle mSavedInstanceState) {
                  super.onCreate(mSavedInstanceState);
                  requestWindowFeature(Window.FEATURE_NO_TITLE);
                  getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                          WindowManager.LayoutParams.FLAG_FULLSCREEN);
                  setContentView(R.layout.main);
                  mScan = (Button) findViewById(R.id.Scan);
                  check = (Button)findViewById(R.id.check);
  
  
  
                  mScan.setOnClickListener(new View.OnClickListener() {
                      public void onClick(View mView) {
                          mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
                          if (mBluetoothAdapter == null) {
                              Toast.makeText(Main.this, "Message1", 2000).show();
                          } else {
                              if (!mBluetoothAdapter.isEnabled()) {
                                  Intent enableBtIntent = new Intent(
                                          BluetoothAdapter.ACTION_REQUEST_ENABLE);
                                  startActivityForResult(enableBtIntent,
                                          REQUEST_ENABLE_BT);
                              } else {
                                  ListPairedDevices();
                                  Intent connectIntent = new Intent(Main.this,
                                          DeviceListActivity.class);
                                  startActivityForResult(connectIntent,
                                          REQUEST_CONNECT_DEVICE);
                              }
                          }
                      }
                  });
  
                  mPrint = (Button) findViewById(R.id.mPrint);
                  mPrint.setOnClickListener(new View.OnClickListener() {
                      public void onClick(View mView) {
                          Thread t = new Thread() {
                              public void run() {
                                  try {
                                      OutputStream os = mBluetoothSocket
                                              .getOutputStream();
                                      String BILL = "";
  
                                      BILL = "\nInvoice No: ABCDEF28060000005" + "    "
                                              + "04-08-2011\n";
                                      BILL = BILL
                                              + "-----------------------------------------";
                                      BILL = BILL + "\n\n";
                                      BILL = BILL + "Total Qty:" + "      " + "2.0\n";
                                      BILL = BILL + "Total Value:" + "     "
                                              + "17625.0\n";
                                      BILL = BILL
                                              + "-----------------------------------------\n";
                                      os.write(BILL.getBytes());
                                          //This is printer specific code you can comment ==== &gt; Start
  
                                      // Setting height
                                      int gs = 29;
                                      os.write(intToByteArray(gs));
                                      int h = 104;
                                      os.write(intToByteArray(h));
                                      int n = 162;
                                      os.write(intToByteArray(n));
  
                                      // Setting Width
                                      int gs_width = 29;
                                      os.write(intToByteArray(gs_width));
                                      int w = 119;
                                      os.write(intToByteArray(w));
                                      int n_width = 2;
                                      os.write(intToByteArray(n_width));
  
                                      // Print BarCode
                                      int gs1 = 29;
                                      os.write(intToByteArray(gs1));
                                      int k = 107;
                                      os.write(intToByteArray(k));
                                      int m = 73;
                                      os.write(intToByteArray(m));
  
                                      String barCodeVal = "ASDFC028060000005";// "HELLO12345678912345012";
                                      System.out.println("Barcode Length : "
                                              + barCodeVal.length());
                                      int n1 = barCodeVal.length();
                                      os.write(intToByteArray(n1));
  
                                      for (int i = 0; i &lt; barCodeVal.length(); i++) {
                                          os.write((barCodeVal.charAt(i) + "").getBytes());
                                      }
         //printer specific code you can comment ==== &gt; End
                                  } catch (Exception e) {
                                      Log.e("Main", "Exe ", e);
                                  }
                              }
                          };
                          t.start();
                      }
                  });
  
                  mDisc = (Button) findViewById(R.id.dis);
                  mDisc.setOnClickListener(new View.OnClickListener() {
                      public void onClick(View mView) {
                          if (mBluetoothAdapter != null)
                              mBluetoothAdapter.disable();
                      }
                  });
  
              }// onCreate
  
              @Override
              protected void onDestroy() {
                  // TODO Auto-generated method stub
                  super.onDestroy();
                  try {
                      if (mBluetoothSocket != null)
                          mBluetoothSocket.close();
                  } catch (Exception e) {
                      Log.e("Tag", "Exe ", e);
                  }
              }
  
              @Override
              public void onBackPressed() {
                  try {
                      if (mBluetoothSocket != null)
                          mBluetoothSocket.close();
                  } catch (Exception e) {
                      Log.e("Tag", "Exe ", e);
                  }
                  setResult(RESULT_CANCELED);
                  finish();
              }
  
              public void onActivityResult(int mRequestCode, int mResultCode,
                      Intent mDataIntent) {
                  super.onActivityResult(mRequestCode, mResultCode, mDataIntent);
  
                  switch (mRequestCode) {
                  case REQUEST_CONNECT_DEVICE:
                      if (mResultCode == Activity.RESULT_OK) {
                          Bundle mExtra = mDataIntent.getExtras();
                          String mDeviceAddress = mExtra.getString("DeviceAddress");
                          Log.v(TAG, "Coming incoming address " + mDeviceAddress);
                          mBluetoothDevice = mBluetoothAdapter
                                  .getRemoteDevice(mDeviceAddress);
                          mBluetoothConnectProgressDialog = ProgressDialog.show(this,
                                  "Connecting...", mBluetoothDevice.getName() + " : "
                                          + mBluetoothDevice.getAddress(), true, false);
                          Thread mBlutoothConnectThread = new Thread(this);
                          mBlutoothConnectThread.start();
                          // pairToDevice(mBluetoothDevice); This method is replaced by
                          // progress dialog with thread
                      }
                      break;
  
                  case REQUEST_ENABLE_BT:
                      if (mResultCode == Activity.RESULT_OK) {
                          ListPairedDevices();
                          Intent connectIntent = new Intent(Main.this,
                                  DeviceListActivity.class);
                          startActivityForResult(connectIntent, REQUEST_CONNECT_DEVICE);
                      } else {
                          Toast.makeText(Main.this, "Message", 2000).show();
                      }
                      break;
                  }
              }
  
              private void ListPairedDevices() {
                  Set&lt;BluetoothDevice&gt; mPairedDevices = mBluetoothAdapter
                          .getBondedDevices();
                  if (mPairedDevices.size() &gt; 0) {
                      for (BluetoothDevice mDevice : mPairedDevices) {
                          Log.v(TAG, "PairedDevices: " + mDevice.getName() + "  "
                                  + mDevice.getAddress());
                      }
                  }
              }
  
              public void run() {
                  try {
                      mBluetoothSocket = mBluetoothDevice
                              .createRfcommSocketToServiceRecord(applicationUUID);
                      mBluetoothAdapter.cancelDiscovery();
                      mBluetoothSocket.connect();
                      mHandler.sendEmptyMessage(0);
                  } catch (IOException eConnectException) {
                      Log.d(TAG, "CouldNotConnectToSocket", eConnectException);
                      closeSocket(mBluetoothSocket);
                      return;
                  }
              }
  
              private void closeSocket(BluetoothSocket nOpenSocket) {
                  try {
                      nOpenSocket.close();
                      Log.d(TAG, "SocketClosed");
                  } catch (IOException ex) {
                      Log.d(TAG, "CouldNotCloseSocket");
                  }
              }
  
              private Handler mHandler = new Handler() {
                  @Override
                  public void handleMessage(Message msg) {
                      mBluetoothConnectProgressDialog.dismiss();
                      Toast.makeText(Main.this, "DeviceConnected", 5000).show();
                  }
              };
  
              public static byte intToByteArray(int value) {
                  byte[] b = ByteBuffer.allocate(4).putInt(value).array();
  
                  for (int k = 0; k &lt; b.length; k++) {
                      System.out.println("Selva  [" + k + "] = " + "0x"
                              + UnicodeFormatter.byteToHex(b[k]));
                  }
  
                  return b[3];
              }
  
              public byte[] sel(int val) {
                  ByteBuffer buffer = ByteBuffer.allocate(2);
                  buffer.putInt(val);
                  buffer.flip();
                  return buffer.array();
              }
  </code></pre>
  
  <p><strong>DeviceListActivity</strong></p>
  
  <pre><code> public class DeviceListActivity extends Activity 
      { 
      protected static final String TAG = "TAG"; 
      private BluetoothAdapter mBluetoothAdapter; 
      private ArrayAdapter&lt;String&gt; mPairedDevicesArrayAdapter; 
  
      @Override 
      protected void onCreate(Bundle mSavedInstanceState) 
      { 
          super.onCreate(mSavedInstanceState); 
          requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); 
          setContentView(R.layout.device_list); 
  
          setResult(Activity.RESULT_CANCELED); 
          mPairedDevicesArrayAdapter = new ArrayAdapter&lt;String&gt;(this, R.layout.device_name); 
  
          ListView mPairedListView = (ListView) findViewById(R.id.paired_devices); 
          mPairedListView.setAdapter(mPairedDevicesArrayAdapter); 
          mPairedListView.setOnItemClickListener(mDeviceClickListener); 
  
          mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); 
          Set&lt;BluetoothDevice&gt; mPairedDevices = mBluetoothAdapter.getBondedDevices(); 
  
          if (mPairedDevices.size() &gt; 0) 
          { 
              findViewById(R.id.title_paired_devices).setVisibility(View.VISIBLE); 
              for (BluetoothDevice mDevice : mPairedDevices) 
              { 
                  mPairedDevicesArrayAdapter.add(mDevice.getName() + "\n" + mDevice.getAddress()); 
              } 
          } 
          else 
          { 
              String mNoDevices = "None Paired";//getResources().getText(R.string.none_paired).toString(); 
              mPairedDevicesArrayAdapter.add(mNoDevices); 
          } 
      } 
  
      @Override 
      protected void onDestroy() 
      { 
          super.onDestroy(); 
          if (mBluetoothAdapter != null) 
          { 
              mBluetoothAdapter.cancelDiscovery(); 
          } 
      } 
  
      private OnItemClickListener mDeviceClickListener = new OnItemClickListener() 
      { 
          public void onItemClick(AdapterView&lt;?&gt; mAdapterView, View mView, int mPosition, long mLong) 
          { 
              mBluetoothAdapter.cancelDiscovery(); 
              String mDeviceInfo = ((TextView) mView).getText().toString(); 
              String mDeviceAddress = mDeviceInfo.substring(mDeviceInfo.length() - 17); 
              Log.v(TAG, "Device_Address " + mDeviceAddress); 
  
              Bundle mBundle = new Bundle(); 
              mBundle.putString("DeviceAddress", mDeviceAddress); 
              Intent mBackIntent = new Intent(); 
              mBackIntent.putExtras(mBundle); 
              setResult(Activity.RESULT_OK, mBackIntent); 
              finish(); 
          } 
      }; 
  
   } 
  
          }
  </code></pre>
  
  <p><strong>UnicodeFormatter:</strong></p>
  
  <pre><code>public class UnicodeFormatter {
  
      static public String byteToHex(byte b) {
              // Returns hex String representation of byte b
              char hexDigit[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
                      'a', 'b', 'c', 'd', 'e', 'f' };
              char[] array = { hexDigit[(b &gt;&gt; 4) &amp; 0x0f], hexDigit[b &amp; 0x0f] };
              return new String(array);
      }
  
      static public String charToHex(char c) {
              // Returns hex String representation of char c
              byte hi = (byte) (c &gt;&gt;&gt; 8);
              byte lo = (byte) (c &amp; 0xff);
              return byteToHex(hi) + byteToHex(lo);
      }
  
  } 
  </code></pre>
  
  <p><strong>Manifest.xml</strong></p>
  
  <pre><code>&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.printapplication"
      android:versionCode="1"
      android:versionName="1.0" &gt;
  
      &lt;uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /&gt;
      &lt;uses-permission android:name="android.permission.BLUETOOTH" /&gt;
        &lt;permission
          android:name="android.permission.BLUETOOTH"
          android:label="BLUETOOTH" &gt;
      &lt;/permission&gt;
      &lt;permission android:name="android.permission.BLUETOOTH_ADMIN" &gt;
      &lt;/permission&gt;
  
      &lt;uses-sdk
          android:minSdkVersion="15"
          android:targetSdkVersion="21" /&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" &gt;
          &lt;activity
              android:name=".Main"
              android:label="@string/app_name" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;activity
              android:name=".DeviceListActivity"
              android:label="@string/app_name" &gt;
  
          &lt;/activity&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>