2012-12-13 33 views
7

Bir uygulamayı uyguluyorum.Bluetooth aracılığıyla zebra mz320 yazıcıya nasıl geçilir?

Benim gereksinimime dayanarak, bir mobil telefon aracılığıyla bir zebra mz320 yazıcıdan bir çıktı almak istiyorum. Ben printer bluetoth.

ben eşleştirmek çalışmaktır mobile bluetooth gelen bir çift yapmaya çalışıyorum

, yazıcı Tip 1234 veya marka bağlantı için 0000 PIN" gibi bir mesaj atar.

aynı daktilo PIN'i.

Ama yazıcı mobil cihazım eşleşmediğinizden edilir.

O com.zebra.android.comm.ZebraPrinterConnectionException: Could not connect to printer: Unable to start Service Discovery

gibi bir istisna atar

Çözümü bilen varsa, lütfen bana yardım edin.
Önceden teşekkürler.

+0

Ben aynı sorun var. Bir çözüm buldunuz mu? –

+0

Yazıcının UUID'sini almanız gerekir. listenUsingRfcommWithServiceRecord (Dize adı, UUID uuid) – SeahawksRdaBest

cevap

1

UUID'ler listesi bkz. here. Bağlantı yapmak için kuyrukta bu parçacıkları birini veya tümünü denemelisiniz:

@TargetApi (10) özel BluetoothSocket connectDeviceUsingAPI10() atar IOException {

BluetoothSocket socket = null; 
IOException ioex = null; 
int port = 1; // may be from 1 to 14 if I'm not confused 
UUID SPP_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"); 

// way #0. Connect using workaround for Android < 2.3 
try { 
    if (!isThreadActive) 
     return null; 
    Log.d("Try via API10: createInsecureRfcommSocketToServiceRecord"); 
    socket = mDevice.createInsecureRfcommSocketToServiceRecord(SPP_UUID); // or RFCOMM_UUID); 
    } catch (IOException e) { ioex = e; } 
     if (socket != null && ioex == null) { 
      try { 
       socket.connect(); 
       setStreams(socket.getOutputStream(), socket.getInputStream()); 
      } catch (IOException ex) { 
       ioex = ex; 
       try { 
        socket.close(); 
       } catch (IOException e) { 
       } finally { 
        socket = null; 
       } 
      } 
     } 
     if (socket != null && ioex == null) { 
      return socket; 

     } 

     ioex = null; 
     socket = null; 
     // way #1. Using standard secure connection procedure via UUID 
     try { 
      if (!isThreadActive) 
       return null; 
      Log.d("Try via API10: createRfcommSocketToServiceRecord"); 
      socket = mDevice 
        .createRfcommSocketToServiceRecord(SPP_UUID);// or RFCOMM_UUID 
     } catch (IOException e) { 
      ioex = e; 
     } 
     if (socket != null && ioex == null) { 
      try { 
       socket.connect(); 
       setStreams(socket.getOutputStream(), socket.getInputStream()); 
      } catch (IOException ex) { 
       ioex = ex; 
       try { 
        socket.close(); 
       } catch (IOException e) { 
       } finally { 
        socket = null; 
       } 
      } 
     } 
     if (socket != null && ioex == null) { 
      return socket; 
     } 

     // way #2. Using hidden api procedure with insecure socket 
     socket = null; 
     ioex = null; 
     // Try to fallback to API5 method 
     try { 
      if (!isThreadActive) 
       return null; 
      Log.d("Try via API10: createInsecureRfcommSocket"); 
      Method m = mDevice.getClass().getMethod(
        "createInsecureRfcommSocket", new Class[] { int.class }); 
      socket = (BluetoothSocket) m.invoke(mDevice, Integer.valueOf(port)); 
     } catch (IOException e) { // ... } 
     if (socket != null && ioex == null) { 
      try { 
       socket.connect(); 
       setStreams(socket.getOutputStream(), socket.getInputStream()); 
      } catch (IOException ex) { 
       ioex = ex; 
       try { 
        socket.close(); 
       } catch (IOException e) { 
       } finally { 
        socket = null; 
       } 
      } 
     } 

     if (socket != null && ioex == null) { 
      return socket; 
     } 

     ioex = null; 
     socket = null; 
     // way #3. Connect using workaround for Android < 2.3 
     try { 
      if (!isThreadActive) 
       return null; 
      Log.d("Try via API10: createRfcommSocket"); 
      Method m = mDevice.getClass().getMethod("createRfcommSocket", 
        new Class[] { int.class }); 
      socket = (BluetoothSocket) m.invoke(mDevice, Integer.valueOf(port)); 
     } catch (IOException e) { 
       ioex = e; 
     } 
     if (socket != null && ioex == null) { 
      try { 
       socket.connect(); 
       setStreams(socket.getOutputStream(), socket.getInputStream()); 
      } catch (IOException ex) { 
       ioex = ex; 
       try { 
        socket.close(); 
       } catch (IOException e) { 
       } finally { 
        socket = null; 
       } 
      } 
     } 
     if (socket != null && ioex == null) { 
      return socket; 
     } 
     return socket; 
    } 
İlgili konular