title: How to detect the model of a Brother printer on Android?
body: <p>I am using Brother's Android SDK for printing documents in a Brother printer. I am currently using a PJ-7626053, but I'd like to be able to support any compatible model in my application. <br/>
  I'd like to be able to detect the printer model dynamically once I have a reference to its <code>BluetoothDevice</code> object.
  Brother's sample code uses a hard coded model (line <code>settings.printerModel = Model.PJ_773;</code> below), but I would like to be able to print to any compatible Brother printer.</p>
  <p>Brother sample code:</p>
  <pre><code>void printImage(Bitmap bitmap) {
      // Specify printer
      final Printer printer = new Printer();
      PrinterInfo settings = printer.getPrinterInfo();
      settings.printerModel = Model.PJ_773;
      settings.port = PrinterInfo.Port.NET;
      settings.ipAddress = &quot;your-printer-ip&quot;;
      settings.workPath = &quot;Context.writable-dir-path&quot;;
  
      // Print Settings
      settings.paperSize = PaperSize.A4;
      settings.printMode = PrinterInfo.PrintMode.FIT_TO_PAGE;
      printer.setPrinterInfo(settings);
  
      // Connect, then print
      new Thread(new Runnable() {
          @Override
          public void run() {
              if (printer.startCommunication()) {
                  PrinterStatus result = printer.printImage(bitmap);
                  if (result.errorCode != ErrorCode.ERROR_NONE) {
                      Log.d(&quot;TAG&quot;, &quot;ERROR - &quot; + result.errorCode);
                  }
                  printer.endCommunication();
              }
          }
      }).start();
  }
  </code></pre>
  <p>Link to sample code page: <a href="https://support.brother.com/g/s/es/htmldoc/mobilesdk/guide/print-image.html#pjmw-series" rel="nofollow noreferrer">https://support.brother.com/g/s/es/htmldoc/mobilesdk/guide/print-image.html#pjmw-series</a></p>
  <p>My code is below. As you can see I am currently using the device name to determine the model which is not ideal. If I simply omit the assignment <code>settings.printerModel = model;</code> , the <code>startCommunication()</code> method returns false and printing fails. <br/>
  <strong>Is there a way to detect the model dynamically and more reliably?</strong></p>
  <pre><code>public static void printTOIFormBitMap(Bitmap bitmap, BluetoothDevice btDevice) throws UnsupportedDeviceException {
      // Specify printer
      final Printer printer = new Printer();
      PrinterInfo settings = printer.getPrinterInfo();
      
      /********* TODO: detect model  *********/
      final String deviceName = btDevice.getName();
      if (deviceName == null) {
          throw new UnsupportedDeviceException();
      }
      PrinterInfo.Model model = null;
      if (deviceName.startsWith(&quot;PJ-762&quot;)) {
          model = PrinterInfo.Model.PJ_762;
      } else if (deviceName.startsWith(&quot;PJ-763&quot;)) {
          model = PrinterInfo.Model.PJ_763;
      }
      if (model == null) {
          throw new UnsupportedDeviceException();
      }
  
      settings.printerModel = model;
      /***************************************/
  
      // For Bluetooth:
      printer.setBluetooth(BluetoothAdapter.getDefaultAdapter());
      settings.port = PrinterInfo.Port.BLUETOOTH;
      settings.macAddress = btDevice.getAddress();
      // Print Settings
      settings.paperSize = PrinterInfo.PaperSize.A4;
      settings.printMode = PrinterInfo.PrintMode.FIT_TO_PAPER;
      settings.printQuality = PrinterInfo.PrintQuality.HIGH_RESOLUTION;
      settings.align = PrinterInfo.Align.CENTER;
  
      settings.isAutoCut = true;
      printer.setPrinterInfo(settings);
  
      new Thread(() -&gt; {
          PrinterStatus result = null;
          boolean startCommunicationSuccess = printer.startCommunication();
          if (startCommunicationSuccess) { 
              result = printer.printImage(bitmap);
              RxBus.getInstance().publish(new PrintDoneEvent(result));
              printer.endCommunication();
          }
      }).start();
  }
  </code></pre>
  <p>I am aware I can alternatively share the document to the Brother iPrint&amp;Scan app or just use Android's native printing feature simply by installing the Brother Print Service Plugin to my phone. Both these options allow printing of any document from any application and I have to ensure only my application can interface with the printer (the mobile phones that run my application are custom configured to only allow installation of predetermined apps), so I assume I have to use the SDK.</p>