2017-11-15 6 views
0

私の一日を無駄にしますが、サーマルプリンタがハーフテキストを受信して​​印刷する理由を理解できませんでした。それは完全に58mm Mini Bluetooth Thermal Printerの仕事です。しかし、サーマルプリンターに入ったらLESHP 80mm Wireless Bluetooth Thermalこのプリンターは半分のテキストのみを受け取ります。Bluetooth Thermal printer print half String

ここに私のコード:

void findBT() { 

    try { 
     mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); 

     if (mBluetoothAdapter == null) { 

     } 

     if (!mBluetoothAdapter.isEnabled()) { 
      Intent enableBluetooth = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); 
      startActivityForResult(enableBluetooth, 0); 
     } 

     Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices(); 

     if (pairedDevices.size() > 0) { 
      for (BluetoothDevice device : pairedDevices) { 

       if (device.getName().contains("Printer")) { 

        mmDevice = device; 

       } 
      } 



     } 
     else { 
      Toast.makeText(this,"device not pair.",Toast.LENGTH_LONG).show(); 
     } 

    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
void SendDateBT() throws IOException { 
    try { 

     // Standard SerialPortService ID 
     UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb"); 


     mmSocket = mmDevice.createRfcommSocketToServiceRecord(uuid); 

     mmSocket.connect(); 
     mmOutputStream = mmSocket.getOutputStream(); 
     mmInputStream = mmSocket.getInputStream(); 
     mmOutputStream.write(mytext.getBytes()); 

     mmOutputStream.flush(); 
     mmOutputStream.close(); 
     mmInputStream.close(); 
     mmSocket.close(); 

    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
} 

私は領収書を印刷したいとき、私はこの2つの関数を呼び出す:

findBT(); 
SendDatBt(); 
+0

接続終了時にデバイスが印刷を停止する可能性はありますか?フラッシュ呼び出し後、20秒間スリープ状態を追加してみてください。もっと印刷されますか?そうであれば、APIがジョブがクリーンな仕方で終了するのを待つ方法を提供しているかどうかを調べます(つまり、任意の時間だけスリープ状態ではない)。 – Hector

+0

印刷された文書についての画像を提供してください – nhoxbypass

+0

私の他のコメントに加えて、EOFを送ろうとしましたか? – Hector

答えて

0

私は多くの検索と私の仕事の後にこれを試しています。

mmOutputStream.write(Mytext.getBytes(Charset.forName("UTF-8"‌​))); 
関連する問題