public BluetoothDevice FindPrinter() { BluetoothDevice currentDevice = null; try { mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (mBluetoothAdapter == null) { throw new Exception("Bluetooth adaptorü bulunamadı"); } if (!mBluetoothAdapter.isEnabled()) { Intent enableBluetooth = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); Activity a = new Activity(); a.startActivityForResult(enableBluetooth, 0); } Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices(); if (pairedDevices.size() > 0) { for (BluetoothDevice device : pairedDevices) { if(device.getName().equals(SharedPreferenceSettings.getPrinterPort(context))) { currentDevice = device; } } } } catch (Exception e) { Toast.makeText(context, e.getMessage(), Toast.LENGTH_SHORT).show(); } return currentDevice; } public void Print() { try { int current = 0; FormatData(); int line = 0; Method m = mmDevice.getClass().getMethod("createRfcommSocket", new Class[] {int.class}); mmSocket = (BluetoothSocket) m.invoke(mmDevice, 1); mmSocket.connect(); while (current < Data.length) { mmOutputStream = mmSocket.getOutputStream(); int len = 256; if (current + 256 > Data.length) { len = Data.length - current; } byte[] temp = new byte[len]; System.arraycopy(Data, current, temp, 0, len); int currentLine = CountLines(temp); line = line + currentLine; mmOutputStream.write(temp); current += len; Thread.sleep(1700); } mmOutputStream.close(); if(mmSocket.isConnected()) mmSocket.close(); } catch (Exception e) { Log.e("Print ERROR", e.getMessage()); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)