title: How I can printing a string on a Pos Printer by Delphi Android with JNI?
body: <p>Hi Community I have a Question to my Delphi Android Application. The Task is it to create a Android App with Delphi that can print a string on a POS Printer (I use the Bixolon SPP-R200II Printer). </p>
  
  <p>For Example the User Start the App and Input in the Textfield 'Hello Printer' than I want that the Printer print that only on of this string. </p>
  
  <p>My Problem is it that if I click on Print that the printer print 'Hello PrinterHello PrinterHello PrinterHello PrinterHello PrinterHello Printer'  to the end of the line :( </p>
  
  <p>For my Applcation I create a class with 4 functions. </p>
  
  <p><strong>GetDeviceList() : TStringList;</strong>
  // With this I get a TStringList with the Bluetooth Devices, this I bind to my ListView</p>
  
  <p><strong>CreateConnectionToBluetoothDevice(device : TListViewItem) : string;</strong>
   //This create a connection to a Bluetooth device </p>
  
  <p><strong>PrintText(text : string) : string;</strong>
   //this is the print function with a string parameter</p>
  
  <p><strong>StringToJA(Data: String; charset: String = '') : TJavaArray;</strong>
   //This is a helpfunction, with the function I can convert a string to a TJavaArray</p>
  
  <p>Here is my AndroidBluetooth class : </p>
  
  <pre><code>unit AndroidBluetooth;
  
  interface
  
    uses
  
      System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
      FMX.ListView,System.math, FMX.Forms,
      Androidapi.JNI.BluetoothAdapter,
      Androidapi.Helpers,
      Androidapi.JNI.JavaTypes,
      Androidapi.JNIBridge,
      Android.JNI.Toast;
  
    type TAndroidBluetooth = class
  
      private
  
      public
  
        devicename : string;
        uid:JUUID;
        targetMAC:string;
        Adapter:JBluetoothAdapter;
        remoteDevice:JBluetoothDevice;
        Sock:JBluetoothSocket;
        ostream:JOutputStream;
        //istream:JInputstream;
  
        constructor create();
  
        function StringToJA(Data: String; charset: String = '') : TJavaArray&lt;Byte&gt;;
        function GetDeviceList() : TStringList;
        function CreateConnectionToBluetoothDevice(device : TListViewItem) : string;
        function PrintText(text : string) : string;
    end;
  
  implementation
  
    // ## Klassenexterne Funktionen ##
  
    {Konstruktor}
    constructor TAndroidBluetooth.create;
    begin
       inherited Create;
    end;
  
    {Funktion: Gibt alle Bluetooth Geräte in der nähe zurück}
    function TAndroidBluetooth.GetDeviceList : TStringList;
    var
      s:string;
      list:TStringList;
    begin
  
      list:=TStringList.Create;
      s:=checkBluetooth;  // Make sure bluetooth is enabled
      Toast(s);
      if pos('disabled',s)&lt;&gt;0 then exit;
  
      uid := TJUUID.JavaClass.fromString(stringtojstring('00001101-0000-1000-8000-00805F9B34FB'));
  
      list.Clear;
      list.AddStrings(getbonded);
  
      result := list;
  
    end;
  
    {Funktion: Stellt eine Verbindung zu einem Bluetooth Gerät her}
    function TAndroidBluetooth.CreateConnectionToBluetoothDevice(device : TListViewItem) : string;
    var
      len,idx,i:integer;
      s:string;
      buffer:TJavaArray&lt;byte&gt;;
  
    begin
       Toast('Selected '+device.Text);
    targetMAC:=device.Detail;
    if trim(targetMAC)='' then exit;
  
    Adapter:=TJBluetoothAdapter.JavaClass.getDefaultAdapter;
    remoteDevice:=Adapter.getRemoteDevice(stringtojstring(targetMAC));
    Toast('Connecting to '+device.Text+' ('+device.Detail+')');
  
    devicename := device.Text;
  
    sock:=remoteDevice.createRfcommSocketToServiceRecord(uid);
  
    try sock.connect;
    except Toast('Could not create service record!');
    end;
    if not sock.isConnected then
    begin
      Toast('Failed to connect to '+targetMAC+'! Try again...');
      exit;
    end;
    Toast('Connected!');
  
    ostream:=sock.getOutputStream;
    //istream:=sock.getInputStream;
  
      Application.ProcessMessages;
      ostream.write(ord(255)); //
      ostream.write(ord(255)); // get device id   (nur Chitanda)
      sleep(200);
  
    end;
  
    {Funktion: Druckt einen String auf einem Bluetooth Gerät}
    function TAndroidBluetooth.PrintText(text : string) : string;
    var
      txt: string;
      data: TJavaArray&lt;Byte&gt;;
      sendText : TJavaArray&lt;Byte&gt;;
    begin
        txt := text;
        data := StringToJA(txt,'iso8859-2');
  
        sendText := TJavaArray&lt;Byte&gt;.Create(3);
        sendText.Items[0] := $1B;
        sendText.Items[1] := $74;
        sendText.Items[2] := Byte(23);
  
        ostream.write(sendText);
        ostream.write(data);
  
     end;
  
     {Funktion: Konvertiert ein String in ein TJavaArray&lt;Byte&gt;}
     function TAndroidBluetooth.StringToJA(Data: String; charset: String = '') : TJavaArray&lt;Byte&gt;;
     var
      Encoding: TEncoding;
      Arr: TBytes;
      len: integer;
     begin
    if charset &lt;&gt; '' then
      Encoding := TEncoding.GetEncoding(charset)
      else
      Encoding := TEncoding.Default;
      Arr := Encoding.GetBytes(Data);
      len := Length(Arr);
      Result := TJavaArray&lt;Byte&gt;.Create(len);
      if len &gt; 0 then Move(Arr[0], Result.Data^, len);
      end;
  
  end.
  </code></pre>
  
  <p>I hope I get help :)  </p>