Domanda

hello I connect my device android to printers, of the way follows.

bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
      BluetoothDevice bluetakebt220 =
bluetoothAdapter.getRemoteDevice(obj.getMac().toString());
      BluetoothSocket mBTsocket= null;
      bluetoothAdapter.cancelDiscovery();  
       UUID num = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
       mBTsocket = bluetakebt220.createRfcommSocketToServiceRecord(num);
       mBTsocket.connect();

this works well for for most devices, but some do not connected, ¿that can be due?

È stato utile?

Soluzione 2

the device acts equal, simply does not establish proper connection , but yes allow write in

Here is the code if someone can help

UUID num = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
  bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
  BluetoothDevice bluetakebt220 = bluetoothAdapter.getRemoteDevice(obj.getMac().toString());//PRINTER ADAPTER FOR LPT BLUETAKE BT220
  BluetoothSocket mBTsocket= null;
  mBTsocket = bluetakebt220.createRfcommSocketToServiceRecord(num);
  bluetoothAdapter.cancelDiscovery();    
  mBTsocket.connect();
  OutputStream os = **mBTsocket**.getOutputStream();
  os.flush();
  byte[] CPCLFormat = null;
  PCLFormat = objImpresion.getTexto().getBytes("utf-8");
  os.write(CPCLFormat);//se imprime el texto
  os.flush();
  os.close();

.I simply comment msocket.isConnected and write directly after open connection. i don´t why happen

Altri suggerimenti

The most obvious reason I can think of is the UUID's do not match up. If you are making a generic app you need to have the UUID of each printer. This can be done in the form of a case switch statement.

Code

switch(Mac Address) {
  case (Mac Address 1) 
     UUID = xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx

  case (Mac Address 2): 
     UUID = xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx

  default: 
     UUID = 00001101-0000-1000-8000-00805F9B34FB;

The reason why most of the time your connections works is because 00001101-0000-1000-8000-00805F9B34FB is the generic ID for most off shelf hardware devices (keyboards,mouses,printers,scanners etc). The minute your UUID does not match a connection cannot occur. Read this for more info about UUID's.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top