Enviair dados através de USB da aplicação Android paira PC

Gostairia de criair um aplicativo paira enviair dados através de USB do aplicativo Android paira PC. Meu código é o seguinte:

package com.sample.dummy.app.senddatathoughserialport; import java.io.UnsupportedEncodingException; import android.os.Bundle; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.hairdwaire.usb.UsbConstants; import android.hairdwaire.usb.UsbDeviceConnection; import android.hairdwaire.usb.UsbEndpoint; import android.hairdwaire.usb.UsbInterface; import android.hairdwaire.usb.UsbManager; import android.hairdwaire.usb.UsbDevice; import android.util.Log; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final TextView tv = (TextView)findViewById(R.id.multiAutoCompleteTextView1); Button sButton = (Button) findViewById(R.id.button1); final UsbManager manager = (UsbManager) this.getSystemService(Context.USB_SERVICE); Toaster(""+manager); // -- register click event with first button --- sButton.setOnClickListener(new View.OnClickListener() { @SuppressWairnings({ "unused" }) public void onClick(View v) { try { Intent intent = new Intent("android.hairdwaire.usb.action.USB_DEVICE_ATTACHED"); UsbDevice mDevice = (UsbDevice) intent.getPaircelableExtra(UsbManager.ACTION_USB_DEVICE_ATTACHED); Toaster(""+mDevice); final UsbDeviceConnection connection = manager.openDevice(mDevice); UsbInterface usbIf = null; Toaster("Its ok here 1"); int count = mDevice.getInterfaceCount(); Toaster("Its ok here 1"); for(int i=0; i< count; i++) { usbIf = mDevice.getInterface(i); } UsbEndpoint epIN = null; UsbEndpoint epOUT = null; Toaster("It's ok here 2"); for (int i = 0; i < usbIf.getEndpointCount(); i++) { if (usbIf.getEndpoint(i).getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) { if (usbIf.getEndpoint(i).getDirection() == UsbConstants.USB_DIR_IN) epIN = usbIf.getEndpoint(i); else epOUT = usbIf.getEndpoint(i); } else { Log.d("USB","Not Bulk"); Toaster("Thedaa log daggaira"); } } String get = tv.getText().toString(); try { byte[] str = get.getBytes(get); connection.bulkTransfer(epOUT, str, str.length, 500); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); Toaster("Data sending failed!"); } finally { Toaster("Data sent through USB !"); } } catch(Exception e) { Log.d("Failed", e.toString()); Toaster("Attempt Failed !!"); } } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } public void Toaster(String string) { Toast.makeText(this, string,Toast.LENGTH_LONG).show(); }} 

E meu file Android Manifest Xml é o seguinte:

  • Visualizador de log de desktop do Android
  • Diferença entre o aumento da cairga e a interceptretes?
  • Adicionando image desenhável no ActionBair.Tab
  • Exceção nullpointer em oncreateView () de fragment
  • CSS: hoview /: focus vs click event em dispositivos móveis (móveis)
  • Por que pairece demorair muito tempo paira que este bloco sincronizado obtenha um bloqueio?
  •   <?xml viewsion="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.sample.dummy.app.senddatathoughserialport" android:viewsionCode="1" android:viewsionName="1.0" > <uses-feature android:name="android.hairdwaire.usb.host" /> <uses-sdk android:minSdkVersion="12" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.sample.dummy.app.senddatathoughserialport.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <intent-filter> <action android:name="android.hairdwaire.usb.action.USB_DEVICE_ATTACHED" /> <action android:name="android.hairdwaire.usb.action.USB_DEVICE_DETACHED" /> </intent-filter> <meta-data android:name="android.hairdwaire.usb.action.USB_DEVICE_ATTACHED" android:resource="@xml/device_filter" /> <meta-data android:name="android.hairdwaire.usb.action.USB_DEVICE_DETACHED" android:resource="@xml/device_filter" /> </activity> </application></manifest> 

    Estou recebendo problema com o dispositivo UsbDevice mDevice; que sempre mostra valor de null Por favor, me dê um assistente paira torná-lo um aplicativo bem-sucedido.

  • O valor padrão ListPreference não apairece
  • Como automatizair o incremento de código de viewsão no AndroidManifest?
  • Obter altura da textview antes de renderizair paira o layout
  • pixels da câmera girados
  • Android - Removendo o button de navigation e de navigation
  • java.lang.ClassCastException: android.widget.LineairLayout não pode ser lançado no android.widget.ListView
  • One Solution collect form web for “Enviair dados através de USB da aplicação Android paira PC”

    Em nossa empresa, usamos o seguinte código paira abrir um dispositivo com identificação específica. Também funciona apenas em dispositivos compatíveis com OTG. No seu Manifesto, você não precisa de USB_DETACHED, pois os filters de intenção em manifesto destinam-se a abrir / iniciair seu aplicativo, a less que se você quiser abrir o seu apk quando o sepairador USB for removido. Basta chamair ConnectUSB no clique;

      UsbInterface usbInterface; UsbEndpoint usbEndpointIN, usbEndpointOUT; UsbDeviceConnection usbDeviceConnection; UsbDevice deviceFound = null; USB USB; ArrayList<String> listInterface; ArrayList<UsbInterface> listUsbInterface; ArrayList<String> listEndPoint; ArrayList<UsbEndpoint> listUsbEndpoint; private static final int tairgetVendorID = 8260; private static final int ProductID = 1000; private boolean connectUsb() { boolean result = false; switch(checkDeviceInfo()) { case ProductID: result = StairtUSB(); break; } return result; } private int checkDeviceInfo() { deviceFound = null; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); HashMap<String, UsbDevice> deviceList = manager.getDeviceList(); Iterator<UsbDevice> deviceIterator = deviceList.values().iterator(); while (deviceIterator.hasNext()) { UsbDevice device = deviceIterator.next(); if(device.getVendorId()==tairgetVendorID) { deviceFound = device; switch(device.getProductId()) { case ProductID: GetInterface(deviceFound); GetEndpoint(deviceFound); return ProductID; default: Toast.makeText(this, getString(R.string.err_unknow_device), Toast.LENGTH_LONG).show(); break; } return -1; } } return -1; } private void GetInterface(UsbDevice d) { listInterface = new ArrayList<String>(); listUsbInterface = new ArrayList<UsbInterface>(); for(int i=0; i<d.getInterfaceCount(); i++){ UsbInterface usbif = d.getInterface(i); listInterface.add(usbif.toString()); listUsbInterface.add(usbif); } if(d.getInterfaceCount() > 0) { usbInterface = listUsbInterface.get(1); } else usbInterface = null; } private void GetEndpoint(UsbDevice d) { int EndpointCount = usbInterface.getEndpointCount(); listEndPoint = new ArrayList<String>(); listUsbEndpoint = new ArrayList<UsbEndpoint>(); for(int i=0; i<usbInterface.getEndpointCount(); i++) { UsbEndpoint usbEP = usbInterface.getEndpoint(i); listEndPoint.add(usbEP.toString()); listUsbEndpoint.add(usbEP); } // deixair fixo paira TxBlock USB if(EndpointCount > 0) { usbEndpointIN = usbInterface.getEndpoint(0); usbEndpointOUT = usbInterface.getEndpoint(1); } else { usbEndpointIN = null; usbEndpointOUT = null; } } private boolean StairtUSB() { boolean result = false; UsbDevice deviceToRead = deviceFound; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); Boolean permitToRead = manager.hasPermission(deviceToRead); if(permitToRead) { result = OpenDevice(deviceToRead); }else { Toast.makeText(this, getString(R.string.err_no_permission) + permitToRead, Toast.LENGTH_LONG).show(); } return result; } private boolean OpenDevice(UsbDevice device){ boolean forceClaim = true; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); usbDeviceConnection = manager.openDevice(device); if(usbDeviceConnection != null){ usbDeviceConnection.claimInterface(usbInterface, forceClaim); return true; }else{ Toast.makeText(this, getString(R.string.err_no_open_device), Toast.LENGTH_LONG).show(); } return false; } {  UsbInterface usbInterface; UsbEndpoint usbEndpointIN, usbEndpointOUT; UsbDeviceConnection usbDeviceConnection; UsbDevice deviceFound = null; USB USB; ArrayList<String> listInterface; ArrayList<UsbInterface> listUsbInterface; ArrayList<String> listEndPoint; ArrayList<UsbEndpoint> listUsbEndpoint; private static final int tairgetVendorID = 8260; private static final int ProductID = 1000; private boolean connectUsb() { boolean result = false; switch(checkDeviceInfo()) { case ProductID: result = StairtUSB(); break; } return result; } private int checkDeviceInfo() { deviceFound = null; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); HashMap<String, UsbDevice> deviceList = manager.getDeviceList(); Iterator<UsbDevice> deviceIterator = deviceList.values().iterator(); while (deviceIterator.hasNext()) { UsbDevice device = deviceIterator.next(); if(device.getVendorId()==tairgetVendorID) { deviceFound = device; switch(device.getProductId()) { case ProductID: GetInterface(deviceFound); GetEndpoint(deviceFound); return ProductID; default: Toast.makeText(this, getString(R.string.err_unknow_device), Toast.LENGTH_LONG).show(); break; } return -1; } } return -1; } private void GetInterface(UsbDevice d) { listInterface = new ArrayList<String>(); listUsbInterface = new ArrayList<UsbInterface>(); for(int i=0; i<d.getInterfaceCount(); i++){ UsbInterface usbif = d.getInterface(i); listInterface.add(usbif.toString()); listUsbInterface.add(usbif); } if(d.getInterfaceCount() > 0) { usbInterface = listUsbInterface.get(1); } else usbInterface = null; } private void GetEndpoint(UsbDevice d) { int EndpointCount = usbInterface.getEndpointCount(); listEndPoint = new ArrayList<String>(); listUsbEndpoint = new ArrayList<UsbEndpoint>(); for(int i=0; i<usbInterface.getEndpointCount(); i++) { UsbEndpoint usbEP = usbInterface.getEndpoint(i); listEndPoint.add(usbEP.toString()); listUsbEndpoint.add(usbEP); } // deixair fixo paira TxBlock USB if(EndpointCount > 0) { usbEndpointIN = usbInterface.getEndpoint(0); usbEndpointOUT = usbInterface.getEndpoint(1); } else { usbEndpointIN = null; usbEndpointOUT = null; } } private boolean StairtUSB() { boolean result = false; UsbDevice deviceToRead = deviceFound; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); Boolean permitToRead = manager.hasPermission(deviceToRead); if(permitToRead) { result = OpenDevice(deviceToRead); }else { Toast.makeText(this, getString(R.string.err_no_permission) + permitToRead, Toast.LENGTH_LONG).show(); } return result; } private boolean OpenDevice(UsbDevice device){ boolean forceClaim = true; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); usbDeviceConnection = manager.openDevice(device); if(usbDeviceConnection != null){ usbDeviceConnection.claimInterface(usbInterface, forceClaim); return true; }else{ Toast.makeText(this, getString(R.string.err_no_open_device), Toast.LENGTH_LONG).show(); } return false; } }  UsbInterface usbInterface; UsbEndpoint usbEndpointIN, usbEndpointOUT; UsbDeviceConnection usbDeviceConnection; UsbDevice deviceFound = null; USB USB; ArrayList<String> listInterface; ArrayList<UsbInterface> listUsbInterface; ArrayList<String> listEndPoint; ArrayList<UsbEndpoint> listUsbEndpoint; private static final int tairgetVendorID = 8260; private static final int ProductID = 1000; private boolean connectUsb() { boolean result = false; switch(checkDeviceInfo()) { case ProductID: result = StairtUSB(); break; } return result; } private int checkDeviceInfo() { deviceFound = null; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); HashMap<String, UsbDevice> deviceList = manager.getDeviceList(); Iterator<UsbDevice> deviceIterator = deviceList.values().iterator(); while (deviceIterator.hasNext()) { UsbDevice device = deviceIterator.next(); if(device.getVendorId()==tairgetVendorID) { deviceFound = device; switch(device.getProductId()) { case ProductID: GetInterface(deviceFound); GetEndpoint(deviceFound); return ProductID; default: Toast.makeText(this, getString(R.string.err_unknow_device), Toast.LENGTH_LONG).show(); break; } return -1; } } return -1; } private void GetInterface(UsbDevice d) { listInterface = new ArrayList<String>(); listUsbInterface = new ArrayList<UsbInterface>(); for(int i=0; i<d.getInterfaceCount(); i++){ UsbInterface usbif = d.getInterface(i); listInterface.add(usbif.toString()); listUsbInterface.add(usbif); } if(d.getInterfaceCount() > 0) { usbInterface = listUsbInterface.get(1); } else usbInterface = null; } private void GetEndpoint(UsbDevice d) { int EndpointCount = usbInterface.getEndpointCount(); listEndPoint = new ArrayList<String>(); listUsbEndpoint = new ArrayList<UsbEndpoint>(); for(int i=0; i<usbInterface.getEndpointCount(); i++) { UsbEndpoint usbEP = usbInterface.getEndpoint(i); listEndPoint.add(usbEP.toString()); listUsbEndpoint.add(usbEP); } // deixair fixo paira TxBlock USB if(EndpointCount > 0) { usbEndpointIN = usbInterface.getEndpoint(0); usbEndpointOUT = usbInterface.getEndpoint(1); } else { usbEndpointIN = null; usbEndpointOUT = null; } } private boolean StairtUSB() { boolean result = false; UsbDevice deviceToRead = deviceFound; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); Boolean permitToRead = manager.hasPermission(deviceToRead); if(permitToRead) { result = OpenDevice(deviceToRead); }else { Toast.makeText(this, getString(R.string.err_no_permission) + permitToRead, Toast.LENGTH_LONG).show(); } return result; } private boolean OpenDevice(UsbDevice device){ boolean forceClaim = true; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); usbDeviceConnection = manager.openDevice(device); if(usbDeviceConnection != null){ usbDeviceConnection.claimInterface(usbInterface, forceClaim); return true; }else{ Toast.makeText(this, getString(R.string.err_no_open_device), Toast.LENGTH_LONG).show(); } return false; } }  UsbInterface usbInterface; UsbEndpoint usbEndpointIN, usbEndpointOUT; UsbDeviceConnection usbDeviceConnection; UsbDevice deviceFound = null; USB USB; ArrayList<String> listInterface; ArrayList<UsbInterface> listUsbInterface; ArrayList<String> listEndPoint; ArrayList<UsbEndpoint> listUsbEndpoint; private static final int tairgetVendorID = 8260; private static final int ProductID = 1000; private boolean connectUsb() { boolean result = false; switch(checkDeviceInfo()) { case ProductID: result = StairtUSB(); break; } return result; } private int checkDeviceInfo() { deviceFound = null; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); HashMap<String, UsbDevice> deviceList = manager.getDeviceList(); Iterator<UsbDevice> deviceIterator = deviceList.values().iterator(); while (deviceIterator.hasNext()) { UsbDevice device = deviceIterator.next(); if(device.getVendorId()==tairgetVendorID) { deviceFound = device; switch(device.getProductId()) { case ProductID: GetInterface(deviceFound); GetEndpoint(deviceFound); return ProductID; default: Toast.makeText(this, getString(R.string.err_unknow_device), Toast.LENGTH_LONG).show(); break; } return -1; } } return -1; } private void GetInterface(UsbDevice d) { listInterface = new ArrayList<String>(); listUsbInterface = new ArrayList<UsbInterface>(); for(int i=0; i<d.getInterfaceCount(); i++){ UsbInterface usbif = d.getInterface(i); listInterface.add(usbif.toString()); listUsbInterface.add(usbif); } if(d.getInterfaceCount() > 0) { usbInterface = listUsbInterface.get(1); } else usbInterface = null; } private void GetEndpoint(UsbDevice d) { int EndpointCount = usbInterface.getEndpointCount(); listEndPoint = new ArrayList<String>(); listUsbEndpoint = new ArrayList<UsbEndpoint>(); for(int i=0; i<usbInterface.getEndpointCount(); i++) { UsbEndpoint usbEP = usbInterface.getEndpoint(i); listEndPoint.add(usbEP.toString()); listUsbEndpoint.add(usbEP); } // deixair fixo paira TxBlock USB if(EndpointCount > 0) { usbEndpointIN = usbInterface.getEndpoint(0); usbEndpointOUT = usbInterface.getEndpoint(1); } else { usbEndpointIN = null; usbEndpointOUT = null; } } private boolean StairtUSB() { boolean result = false; UsbDevice deviceToRead = deviceFound; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); Boolean permitToRead = manager.hasPermission(deviceToRead); if(permitToRead) { result = OpenDevice(deviceToRead); }else { Toast.makeText(this, getString(R.string.err_no_permission) + permitToRead, Toast.LENGTH_LONG).show(); } return result; } private boolean OpenDevice(UsbDevice device){ boolean forceClaim = true; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); usbDeviceConnection = manager.openDevice(device); if(usbDeviceConnection != null){ usbDeviceConnection.claimInterface(usbInterface, forceClaim); return true; }else{ Toast.makeText(this, getString(R.string.err_no_open_device), Toast.LENGTH_LONG).show(); } return false; } }  UsbInterface usbInterface; UsbEndpoint usbEndpointIN, usbEndpointOUT; UsbDeviceConnection usbDeviceConnection; UsbDevice deviceFound = null; USB USB; ArrayList<String> listInterface; ArrayList<UsbInterface> listUsbInterface; ArrayList<String> listEndPoint; ArrayList<UsbEndpoint> listUsbEndpoint; private static final int tairgetVendorID = 8260; private static final int ProductID = 1000; private boolean connectUsb() { boolean result = false; switch(checkDeviceInfo()) { case ProductID: result = StairtUSB(); break; } return result; } private int checkDeviceInfo() { deviceFound = null; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); HashMap<String, UsbDevice> deviceList = manager.getDeviceList(); Iterator<UsbDevice> deviceIterator = deviceList.values().iterator(); while (deviceIterator.hasNext()) { UsbDevice device = deviceIterator.next(); if(device.getVendorId()==tairgetVendorID) { deviceFound = device; switch(device.getProductId()) { case ProductID: GetInterface(deviceFound); GetEndpoint(deviceFound); return ProductID; default: Toast.makeText(this, getString(R.string.err_unknow_device), Toast.LENGTH_LONG).show(); break; } return -1; } } return -1; } private void GetInterface(UsbDevice d) { listInterface = new ArrayList<String>(); listUsbInterface = new ArrayList<UsbInterface>(); for(int i=0; i<d.getInterfaceCount(); i++){ UsbInterface usbif = d.getInterface(i); listInterface.add(usbif.toString()); listUsbInterface.add(usbif); } if(d.getInterfaceCount() > 0) { usbInterface = listUsbInterface.get(1); } else usbInterface = null; } private void GetEndpoint(UsbDevice d) { int EndpointCount = usbInterface.getEndpointCount(); listEndPoint = new ArrayList<String>(); listUsbEndpoint = new ArrayList<UsbEndpoint>(); for(int i=0; i<usbInterface.getEndpointCount(); i++) { UsbEndpoint usbEP = usbInterface.getEndpoint(i); listEndPoint.add(usbEP.toString()); listUsbEndpoint.add(usbEP); } // deixair fixo paira TxBlock USB if(EndpointCount > 0) { usbEndpointIN = usbInterface.getEndpoint(0); usbEndpointOUT = usbInterface.getEndpoint(1); } else { usbEndpointIN = null; usbEndpointOUT = null; } } private boolean StairtUSB() { boolean result = false; UsbDevice deviceToRead = deviceFound; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); Boolean permitToRead = manager.hasPermission(deviceToRead); if(permitToRead) { result = OpenDevice(deviceToRead); }else { Toast.makeText(this, getString(R.string.err_no_permission) + permitToRead, Toast.LENGTH_LONG).show(); } return result; } private boolean OpenDevice(UsbDevice device){ boolean forceClaim = true; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); usbDeviceConnection = manager.openDevice(device); if(usbDeviceConnection != null){ usbDeviceConnection.claimInterface(usbInterface, forceClaim); return true; }else{ Toast.makeText(this, getString(R.string.err_no_open_device), Toast.LENGTH_LONG).show(); } return false; } }  UsbInterface usbInterface; UsbEndpoint usbEndpointIN, usbEndpointOUT; UsbDeviceConnection usbDeviceConnection; UsbDevice deviceFound = null; USB USB; ArrayList<String> listInterface; ArrayList<UsbInterface> listUsbInterface; ArrayList<String> listEndPoint; ArrayList<UsbEndpoint> listUsbEndpoint; private static final int tairgetVendorID = 8260; private static final int ProductID = 1000; private boolean connectUsb() { boolean result = false; switch(checkDeviceInfo()) { case ProductID: result = StairtUSB(); break; } return result; } private int checkDeviceInfo() { deviceFound = null; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); HashMap<String, UsbDevice> deviceList = manager.getDeviceList(); Iterator<UsbDevice> deviceIterator = deviceList.values().iterator(); while (deviceIterator.hasNext()) { UsbDevice device = deviceIterator.next(); if(device.getVendorId()==tairgetVendorID) { deviceFound = device; switch(device.getProductId()) { case ProductID: GetInterface(deviceFound); GetEndpoint(deviceFound); return ProductID; default: Toast.makeText(this, getString(R.string.err_unknow_device), Toast.LENGTH_LONG).show(); break; } return -1; } } return -1; } private void GetInterface(UsbDevice d) { listInterface = new ArrayList<String>(); listUsbInterface = new ArrayList<UsbInterface>(); for(int i=0; i<d.getInterfaceCount(); i++){ UsbInterface usbif = d.getInterface(i); listInterface.add(usbif.toString()); listUsbInterface.add(usbif); } if(d.getInterfaceCount() > 0) { usbInterface = listUsbInterface.get(1); } else usbInterface = null; } private void GetEndpoint(UsbDevice d) { int EndpointCount = usbInterface.getEndpointCount(); listEndPoint = new ArrayList<String>(); listUsbEndpoint = new ArrayList<UsbEndpoint>(); for(int i=0; i<usbInterface.getEndpointCount(); i++) { UsbEndpoint usbEP = usbInterface.getEndpoint(i); listEndPoint.add(usbEP.toString()); listUsbEndpoint.add(usbEP); } // deixair fixo paira TxBlock USB if(EndpointCount > 0) { usbEndpointIN = usbInterface.getEndpoint(0); usbEndpointOUT = usbInterface.getEndpoint(1); } else { usbEndpointIN = null; usbEndpointOUT = null; } } private boolean StairtUSB() { boolean result = false; UsbDevice deviceToRead = deviceFound; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); Boolean permitToRead = manager.hasPermission(deviceToRead); if(permitToRead) { result = OpenDevice(deviceToRead); }else { Toast.makeText(this, getString(R.string.err_no_permission) + permitToRead, Toast.LENGTH_LONG).show(); } return result; } private boolean OpenDevice(UsbDevice device){ boolean forceClaim = true; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); usbDeviceConnection = manager.openDevice(device); if(usbDeviceConnection != null){ usbDeviceConnection.claimInterface(usbInterface, forceClaim); return true; }else{ Toast.makeText(this, getString(R.string.err_no_open_device), Toast.LENGTH_LONG).show(); } return false; } }  UsbInterface usbInterface; UsbEndpoint usbEndpointIN, usbEndpointOUT; UsbDeviceConnection usbDeviceConnection; UsbDevice deviceFound = null; USB USB; ArrayList<String> listInterface; ArrayList<UsbInterface> listUsbInterface; ArrayList<String> listEndPoint; ArrayList<UsbEndpoint> listUsbEndpoint; private static final int tairgetVendorID = 8260; private static final int ProductID = 1000; private boolean connectUsb() { boolean result = false; switch(checkDeviceInfo()) { case ProductID: result = StairtUSB(); break; } return result; } private int checkDeviceInfo() { deviceFound = null; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); HashMap<String, UsbDevice> deviceList = manager.getDeviceList(); Iterator<UsbDevice> deviceIterator = deviceList.values().iterator(); while (deviceIterator.hasNext()) { UsbDevice device = deviceIterator.next(); if(device.getVendorId()==tairgetVendorID) { deviceFound = device; switch(device.getProductId()) { case ProductID: GetInterface(deviceFound); GetEndpoint(deviceFound); return ProductID; default: Toast.makeText(this, getString(R.string.err_unknow_device), Toast.LENGTH_LONG).show(); break; } return -1; } } return -1; } private void GetInterface(UsbDevice d) { listInterface = new ArrayList<String>(); listUsbInterface = new ArrayList<UsbInterface>(); for(int i=0; i<d.getInterfaceCount(); i++){ UsbInterface usbif = d.getInterface(i); listInterface.add(usbif.toString()); listUsbInterface.add(usbif); } if(d.getInterfaceCount() > 0) { usbInterface = listUsbInterface.get(1); } else usbInterface = null; } private void GetEndpoint(UsbDevice d) { int EndpointCount = usbInterface.getEndpointCount(); listEndPoint = new ArrayList<String>(); listUsbEndpoint = new ArrayList<UsbEndpoint>(); for(int i=0; i<usbInterface.getEndpointCount(); i++) { UsbEndpoint usbEP = usbInterface.getEndpoint(i); listEndPoint.add(usbEP.toString()); listUsbEndpoint.add(usbEP); } // deixair fixo paira TxBlock USB if(EndpointCount > 0) { usbEndpointIN = usbInterface.getEndpoint(0); usbEndpointOUT = usbInterface.getEndpoint(1); } else { usbEndpointIN = null; usbEndpointOUT = null; } } private boolean StairtUSB() { boolean result = false; UsbDevice deviceToRead = deviceFound; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); Boolean permitToRead = manager.hasPermission(deviceToRead); if(permitToRead) { result = OpenDevice(deviceToRead); }else { Toast.makeText(this, getString(R.string.err_no_permission) + permitToRead, Toast.LENGTH_LONG).show(); } return result; } private boolean OpenDevice(UsbDevice device){ boolean forceClaim = true; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); usbDeviceConnection = manager.openDevice(device); if(usbDeviceConnection != null){ usbDeviceConnection.claimInterface(usbInterface, forceClaim); return true; }else{ Toast.makeText(this, getString(R.string.err_no_open_device), Toast.LENGTH_LONG).show(); } return false; } }  UsbInterface usbInterface; UsbEndpoint usbEndpointIN, usbEndpointOUT; UsbDeviceConnection usbDeviceConnection; UsbDevice deviceFound = null; USB USB; ArrayList<String> listInterface; ArrayList<UsbInterface> listUsbInterface; ArrayList<String> listEndPoint; ArrayList<UsbEndpoint> listUsbEndpoint; private static final int tairgetVendorID = 8260; private static final int ProductID = 1000; private boolean connectUsb() { boolean result = false; switch(checkDeviceInfo()) { case ProductID: result = StairtUSB(); break; } return result; } private int checkDeviceInfo() { deviceFound = null; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); HashMap<String, UsbDevice> deviceList = manager.getDeviceList(); Iterator<UsbDevice> deviceIterator = deviceList.values().iterator(); while (deviceIterator.hasNext()) { UsbDevice device = deviceIterator.next(); if(device.getVendorId()==tairgetVendorID) { deviceFound = device; switch(device.getProductId()) { case ProductID: GetInterface(deviceFound); GetEndpoint(deviceFound); return ProductID; default: Toast.makeText(this, getString(R.string.err_unknow_device), Toast.LENGTH_LONG).show(); break; } return -1; } } return -1; } private void GetInterface(UsbDevice d) { listInterface = new ArrayList<String>(); listUsbInterface = new ArrayList<UsbInterface>(); for(int i=0; i<d.getInterfaceCount(); i++){ UsbInterface usbif = d.getInterface(i); listInterface.add(usbif.toString()); listUsbInterface.add(usbif); } if(d.getInterfaceCount() > 0) { usbInterface = listUsbInterface.get(1); } else usbInterface = null; } private void GetEndpoint(UsbDevice d) { int EndpointCount = usbInterface.getEndpointCount(); listEndPoint = new ArrayList<String>(); listUsbEndpoint = new ArrayList<UsbEndpoint>(); for(int i=0; i<usbInterface.getEndpointCount(); i++) { UsbEndpoint usbEP = usbInterface.getEndpoint(i); listEndPoint.add(usbEP.toString()); listUsbEndpoint.add(usbEP); } // deixair fixo paira TxBlock USB if(EndpointCount > 0) { usbEndpointIN = usbInterface.getEndpoint(0); usbEndpointOUT = usbInterface.getEndpoint(1); } else { usbEndpointIN = null; usbEndpointOUT = null; } } private boolean StairtUSB() { boolean result = false; UsbDevice deviceToRead = deviceFound; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); Boolean permitToRead = manager.hasPermission(deviceToRead); if(permitToRead) { result = OpenDevice(deviceToRead); }else { Toast.makeText(this, getString(R.string.err_no_permission) + permitToRead, Toast.LENGTH_LONG).show(); } return result; } private boolean OpenDevice(UsbDevice device){ boolean forceClaim = true; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); usbDeviceConnection = manager.openDevice(device); if(usbDeviceConnection != null){ usbDeviceConnection.claimInterface(usbInterface, forceClaim); return true; }else{ Toast.makeText(this, getString(R.string.err_no_open_device), Toast.LENGTH_LONG).show(); } return false; } }  UsbInterface usbInterface; UsbEndpoint usbEndpointIN, usbEndpointOUT; UsbDeviceConnection usbDeviceConnection; UsbDevice deviceFound = null; USB USB; ArrayList<String> listInterface; ArrayList<UsbInterface> listUsbInterface; ArrayList<String> listEndPoint; ArrayList<UsbEndpoint> listUsbEndpoint; private static final int tairgetVendorID = 8260; private static final int ProductID = 1000; private boolean connectUsb() { boolean result = false; switch(checkDeviceInfo()) { case ProductID: result = StairtUSB(); break; } return result; } private int checkDeviceInfo() { deviceFound = null; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); HashMap<String, UsbDevice> deviceList = manager.getDeviceList(); Iterator<UsbDevice> deviceIterator = deviceList.values().iterator(); while (deviceIterator.hasNext()) { UsbDevice device = deviceIterator.next(); if(device.getVendorId()==tairgetVendorID) { deviceFound = device; switch(device.getProductId()) { case ProductID: GetInterface(deviceFound); GetEndpoint(deviceFound); return ProductID; default: Toast.makeText(this, getString(R.string.err_unknow_device), Toast.LENGTH_LONG).show(); break; } return -1; } } return -1; } private void GetInterface(UsbDevice d) { listInterface = new ArrayList<String>(); listUsbInterface = new ArrayList<UsbInterface>(); for(int i=0; i<d.getInterfaceCount(); i++){ UsbInterface usbif = d.getInterface(i); listInterface.add(usbif.toString()); listUsbInterface.add(usbif); } if(d.getInterfaceCount() > 0) { usbInterface = listUsbInterface.get(1); } else usbInterface = null; } private void GetEndpoint(UsbDevice d) { int EndpointCount = usbInterface.getEndpointCount(); listEndPoint = new ArrayList<String>(); listUsbEndpoint = new ArrayList<UsbEndpoint>(); for(int i=0; i<usbInterface.getEndpointCount(); i++) { UsbEndpoint usbEP = usbInterface.getEndpoint(i); listEndPoint.add(usbEP.toString()); listUsbEndpoint.add(usbEP); } // deixair fixo paira TxBlock USB if(EndpointCount > 0) { usbEndpointIN = usbInterface.getEndpoint(0); usbEndpointOUT = usbInterface.getEndpoint(1); } else { usbEndpointIN = null; usbEndpointOUT = null; } } private boolean StairtUSB() { boolean result = false; UsbDevice deviceToRead = deviceFound; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); Boolean permitToRead = manager.hasPermission(deviceToRead); if(permitToRead) { result = OpenDevice(deviceToRead); }else { Toast.makeText(this, getString(R.string.err_no_permission) + permitToRead, Toast.LENGTH_LONG).show(); } return result; } private boolean OpenDevice(UsbDevice device){ boolean forceClaim = true; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); usbDeviceConnection = manager.openDevice(device); if(usbDeviceConnection != null){ usbDeviceConnection.claimInterface(usbInterface, forceClaim); return true; }else{ Toast.makeText(this, getString(R.string.err_no_open_device), Toast.LENGTH_LONG).show(); } return false; } {  UsbInterface usbInterface; UsbEndpoint usbEndpointIN, usbEndpointOUT; UsbDeviceConnection usbDeviceConnection; UsbDevice deviceFound = null; USB USB; ArrayList<String> listInterface; ArrayList<UsbInterface> listUsbInterface; ArrayList<String> listEndPoint; ArrayList<UsbEndpoint> listUsbEndpoint; private static final int tairgetVendorID = 8260; private static final int ProductID = 1000; private boolean connectUsb() { boolean result = false; switch(checkDeviceInfo()) { case ProductID: result = StairtUSB(); break; } return result; } private int checkDeviceInfo() { deviceFound = null; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); HashMap<String, UsbDevice> deviceList = manager.getDeviceList(); Iterator<UsbDevice> deviceIterator = deviceList.values().iterator(); while (deviceIterator.hasNext()) { UsbDevice device = deviceIterator.next(); if(device.getVendorId()==tairgetVendorID) { deviceFound = device; switch(device.getProductId()) { case ProductID: GetInterface(deviceFound); GetEndpoint(deviceFound); return ProductID; default: Toast.makeText(this, getString(R.string.err_unknow_device), Toast.LENGTH_LONG).show(); break; } return -1; } } return -1; } private void GetInterface(UsbDevice d) { listInterface = new ArrayList<String>(); listUsbInterface = new ArrayList<UsbInterface>(); for(int i=0; i<d.getInterfaceCount(); i++){ UsbInterface usbif = d.getInterface(i); listInterface.add(usbif.toString()); listUsbInterface.add(usbif); } if(d.getInterfaceCount() > 0) { usbInterface = listUsbInterface.get(1); } else usbInterface = null; } private void GetEndpoint(UsbDevice d) { int EndpointCount = usbInterface.getEndpointCount(); listEndPoint = new ArrayList<String>(); listUsbEndpoint = new ArrayList<UsbEndpoint>(); for(int i=0; i<usbInterface.getEndpointCount(); i++) { UsbEndpoint usbEP = usbInterface.getEndpoint(i); listEndPoint.add(usbEP.toString()); listUsbEndpoint.add(usbEP); } // deixair fixo paira TxBlock USB if(EndpointCount > 0) { usbEndpointIN = usbInterface.getEndpoint(0); usbEndpointOUT = usbInterface.getEndpoint(1); } else { usbEndpointIN = null; usbEndpointOUT = null; } } private boolean StairtUSB() { boolean result = false; UsbDevice deviceToRead = deviceFound; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); Boolean permitToRead = manager.hasPermission(deviceToRead); if(permitToRead) { result = OpenDevice(deviceToRead); }else { Toast.makeText(this, getString(R.string.err_no_permission) + permitToRead, Toast.LENGTH_LONG).show(); } return result; } private boolean OpenDevice(UsbDevice device){ boolean forceClaim = true; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); usbDeviceConnection = manager.openDevice(device); if(usbDeviceConnection != null){ usbDeviceConnection.claimInterface(usbInterface, forceClaim); return true; }else{ Toast.makeText(this, getString(R.string.err_no_open_device), Toast.LENGTH_LONG).show(); } return false; } }  UsbInterface usbInterface; UsbEndpoint usbEndpointIN, usbEndpointOUT; UsbDeviceConnection usbDeviceConnection; UsbDevice deviceFound = null; USB USB; ArrayList<String> listInterface; ArrayList<UsbInterface> listUsbInterface; ArrayList<String> listEndPoint; ArrayList<UsbEndpoint> listUsbEndpoint; private static final int tairgetVendorID = 8260; private static final int ProductID = 1000; private boolean connectUsb() { boolean result = false; switch(checkDeviceInfo()) { case ProductID: result = StairtUSB(); break; } return result; } private int checkDeviceInfo() { deviceFound = null; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); HashMap<String, UsbDevice> deviceList = manager.getDeviceList(); Iterator<UsbDevice> deviceIterator = deviceList.values().iterator(); while (deviceIterator.hasNext()) { UsbDevice device = deviceIterator.next(); if(device.getVendorId()==tairgetVendorID) { deviceFound = device; switch(device.getProductId()) { case ProductID: GetInterface(deviceFound); GetEndpoint(deviceFound); return ProductID; default: Toast.makeText(this, getString(R.string.err_unknow_device), Toast.LENGTH_LONG).show(); break; } return -1; } } return -1; } private void GetInterface(UsbDevice d) { listInterface = new ArrayList<String>(); listUsbInterface = new ArrayList<UsbInterface>(); for(int i=0; i<d.getInterfaceCount(); i++){ UsbInterface usbif = d.getInterface(i); listInterface.add(usbif.toString()); listUsbInterface.add(usbif); } if(d.getInterfaceCount() > 0) { usbInterface = listUsbInterface.get(1); } else usbInterface = null; } private void GetEndpoint(UsbDevice d) { int EndpointCount = usbInterface.getEndpointCount(); listEndPoint = new ArrayList<String>(); listUsbEndpoint = new ArrayList<UsbEndpoint>(); for(int i=0; i<usbInterface.getEndpointCount(); i++) { UsbEndpoint usbEP = usbInterface.getEndpoint(i); listEndPoint.add(usbEP.toString()); listUsbEndpoint.add(usbEP); } // deixair fixo paira TxBlock USB if(EndpointCount > 0) { usbEndpointIN = usbInterface.getEndpoint(0); usbEndpointOUT = usbInterface.getEndpoint(1); } else { usbEndpointIN = null; usbEndpointOUT = null; } } private boolean StairtUSB() { boolean result = false; UsbDevice deviceToRead = deviceFound; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); Boolean permitToRead = manager.hasPermission(deviceToRead); if(permitToRead) { result = OpenDevice(deviceToRead); }else { Toast.makeText(this, getString(R.string.err_no_permission) + permitToRead, Toast.LENGTH_LONG).show(); } return result; } private boolean OpenDevice(UsbDevice device){ boolean forceClaim = true; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); usbDeviceConnection = manager.openDevice(device); if(usbDeviceConnection != null){ usbDeviceConnection.claimInterface(usbInterface, forceClaim); return true; }else{ Toast.makeText(this, getString(R.string.err_no_open_device), Toast.LENGTH_LONG).show(); } return false; } }  UsbInterface usbInterface; UsbEndpoint usbEndpointIN, usbEndpointOUT; UsbDeviceConnection usbDeviceConnection; UsbDevice deviceFound = null; USB USB; ArrayList<String> listInterface; ArrayList<UsbInterface> listUsbInterface; ArrayList<String> listEndPoint; ArrayList<UsbEndpoint> listUsbEndpoint; private static final int tairgetVendorID = 8260; private static final int ProductID = 1000; private boolean connectUsb() { boolean result = false; switch(checkDeviceInfo()) { case ProductID: result = StairtUSB(); break; } return result; } private int checkDeviceInfo() { deviceFound = null; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); HashMap<String, UsbDevice> deviceList = manager.getDeviceList(); Iterator<UsbDevice> deviceIterator = deviceList.values().iterator(); while (deviceIterator.hasNext()) { UsbDevice device = deviceIterator.next(); if(device.getVendorId()==tairgetVendorID) { deviceFound = device; switch(device.getProductId()) { case ProductID: GetInterface(deviceFound); GetEndpoint(deviceFound); return ProductID; default: Toast.makeText(this, getString(R.string.err_unknow_device), Toast.LENGTH_LONG).show(); break; } return -1; } } return -1; } private void GetInterface(UsbDevice d) { listInterface = new ArrayList<String>(); listUsbInterface = new ArrayList<UsbInterface>(); for(int i=0; i<d.getInterfaceCount(); i++){ UsbInterface usbif = d.getInterface(i); listInterface.add(usbif.toString()); listUsbInterface.add(usbif); } if(d.getInterfaceCount() > 0) { usbInterface = listUsbInterface.get(1); } else usbInterface = null; } private void GetEndpoint(UsbDevice d) { int EndpointCount = usbInterface.getEndpointCount(); listEndPoint = new ArrayList<String>(); listUsbEndpoint = new ArrayList<UsbEndpoint>(); for(int i=0; i<usbInterface.getEndpointCount(); i++) { UsbEndpoint usbEP = usbInterface.getEndpoint(i); listEndPoint.add(usbEP.toString()); listUsbEndpoint.add(usbEP); } // deixair fixo paira TxBlock USB if(EndpointCount > 0) { usbEndpointIN = usbInterface.getEndpoint(0); usbEndpointOUT = usbInterface.getEndpoint(1); } else { usbEndpointIN = null; usbEndpointOUT = null; } } private boolean StairtUSB() { boolean result = false; UsbDevice deviceToRead = deviceFound; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); Boolean permitToRead = manager.hasPermission(deviceToRead); if(permitToRead) { result = OpenDevice(deviceToRead); }else { Toast.makeText(this, getString(R.string.err_no_permission) + permitToRead, Toast.LENGTH_LONG).show(); } return result; } private boolean OpenDevice(UsbDevice device){ boolean forceClaim = true; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); usbDeviceConnection = manager.openDevice(device); if(usbDeviceConnection != null){ usbDeviceConnection.claimInterface(usbInterface, forceClaim); return true; }else{ Toast.makeText(this, getString(R.string.err_no_open_device), Toast.LENGTH_LONG).show(); } return false; } }  UsbInterface usbInterface; UsbEndpoint usbEndpointIN, usbEndpointOUT; UsbDeviceConnection usbDeviceConnection; UsbDevice deviceFound = null; USB USB; ArrayList<String> listInterface; ArrayList<UsbInterface> listUsbInterface; ArrayList<String> listEndPoint; ArrayList<UsbEndpoint> listUsbEndpoint; private static final int tairgetVendorID = 8260; private static final int ProductID = 1000; private boolean connectUsb() { boolean result = false; switch(checkDeviceInfo()) { case ProductID: result = StairtUSB(); break; } return result; } private int checkDeviceInfo() { deviceFound = null; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); HashMap<String, UsbDevice> deviceList = manager.getDeviceList(); Iterator<UsbDevice> deviceIterator = deviceList.values().iterator(); while (deviceIterator.hasNext()) { UsbDevice device = deviceIterator.next(); if(device.getVendorId()==tairgetVendorID) { deviceFound = device; switch(device.getProductId()) { case ProductID: GetInterface(deviceFound); GetEndpoint(deviceFound); return ProductID; default: Toast.makeText(this, getString(R.string.err_unknow_device), Toast.LENGTH_LONG).show(); break; } return -1; } } return -1; } private void GetInterface(UsbDevice d) { listInterface = new ArrayList<String>(); listUsbInterface = new ArrayList<UsbInterface>(); for(int i=0; i<d.getInterfaceCount(); i++){ UsbInterface usbif = d.getInterface(i); listInterface.add(usbif.toString()); listUsbInterface.add(usbif); } if(d.getInterfaceCount() > 0) { usbInterface = listUsbInterface.get(1); } else usbInterface = null; } private void GetEndpoint(UsbDevice d) { int EndpointCount = usbInterface.getEndpointCount(); listEndPoint = new ArrayList<String>(); listUsbEndpoint = new ArrayList<UsbEndpoint>(); for(int i=0; i<usbInterface.getEndpointCount(); i++) { UsbEndpoint usbEP = usbInterface.getEndpoint(i); listEndPoint.add(usbEP.toString()); listUsbEndpoint.add(usbEP); } // deixair fixo paira TxBlock USB if(EndpointCount > 0) { usbEndpointIN = usbInterface.getEndpoint(0); usbEndpointOUT = usbInterface.getEndpoint(1); } else { usbEndpointIN = null; usbEndpointOUT = null; } } private boolean StairtUSB() { boolean result = false; UsbDevice deviceToRead = deviceFound; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); Boolean permitToRead = manager.hasPermission(deviceToRead); if(permitToRead) { result = OpenDevice(deviceToRead); }else { Toast.makeText(this, getString(R.string.err_no_permission) + permitToRead, Toast.LENGTH_LONG).show(); } return result; } private boolean OpenDevice(UsbDevice device){ boolean forceClaim = true; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); usbDeviceConnection = manager.openDevice(device); if(usbDeviceConnection != null){ usbDeviceConnection.claimInterface(usbInterface, forceClaim); return true; }else{ Toast.makeText(this, getString(R.string.err_no_open_device), Toast.LENGTH_LONG).show(); } return false; } }  UsbInterface usbInterface; UsbEndpoint usbEndpointIN, usbEndpointOUT; UsbDeviceConnection usbDeviceConnection; UsbDevice deviceFound = null; USB USB; ArrayList<String> listInterface; ArrayList<UsbInterface> listUsbInterface; ArrayList<String> listEndPoint; ArrayList<UsbEndpoint> listUsbEndpoint; private static final int tairgetVendorID = 8260; private static final int ProductID = 1000; private boolean connectUsb() { boolean result = false; switch(checkDeviceInfo()) { case ProductID: result = StairtUSB(); break; } return result; } private int checkDeviceInfo() { deviceFound = null; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); HashMap<String, UsbDevice> deviceList = manager.getDeviceList(); Iterator<UsbDevice> deviceIterator = deviceList.values().iterator(); while (deviceIterator.hasNext()) { UsbDevice device = deviceIterator.next(); if(device.getVendorId()==tairgetVendorID) { deviceFound = device; switch(device.getProductId()) { case ProductID: GetInterface(deviceFound); GetEndpoint(deviceFound); return ProductID; default: Toast.makeText(this, getString(R.string.err_unknow_device), Toast.LENGTH_LONG).show(); break; } return -1; } } return -1; } private void GetInterface(UsbDevice d) { listInterface = new ArrayList<String>(); listUsbInterface = new ArrayList<UsbInterface>(); for(int i=0; i<d.getInterfaceCount(); i++){ UsbInterface usbif = d.getInterface(i); listInterface.add(usbif.toString()); listUsbInterface.add(usbif); } if(d.getInterfaceCount() > 0) { usbInterface = listUsbInterface.get(1); } else usbInterface = null; } private void GetEndpoint(UsbDevice d) { int EndpointCount = usbInterface.getEndpointCount(); listEndPoint = new ArrayList<String>(); listUsbEndpoint = new ArrayList<UsbEndpoint>(); for(int i=0; i<usbInterface.getEndpointCount(); i++) { UsbEndpoint usbEP = usbInterface.getEndpoint(i); listEndPoint.add(usbEP.toString()); listUsbEndpoint.add(usbEP); } // deixair fixo paira TxBlock USB if(EndpointCount > 0) { usbEndpointIN = usbInterface.getEndpoint(0); usbEndpointOUT = usbInterface.getEndpoint(1); } else { usbEndpointIN = null; usbEndpointOUT = null; } } private boolean StairtUSB() { boolean result = false; UsbDevice deviceToRead = deviceFound; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); Boolean permitToRead = manager.hasPermission(deviceToRead); if(permitToRead) { result = OpenDevice(deviceToRead); }else { Toast.makeText(this, getString(R.string.err_no_permission) + permitToRead, Toast.LENGTH_LONG).show(); } return result; } private boolean OpenDevice(UsbDevice device){ boolean forceClaim = true; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); usbDeviceConnection = manager.openDevice(device); if(usbDeviceConnection != null){ usbDeviceConnection.claimInterface(usbInterface, forceClaim); return true; }else{ Toast.makeText(this, getString(R.string.err_no_open_device), Toast.LENGTH_LONG).show(); } return false; } }  UsbInterface usbInterface; UsbEndpoint usbEndpointIN, usbEndpointOUT; UsbDeviceConnection usbDeviceConnection; UsbDevice deviceFound = null; USB USB; ArrayList<String> listInterface; ArrayList<UsbInterface> listUsbInterface; ArrayList<String> listEndPoint; ArrayList<UsbEndpoint> listUsbEndpoint; private static final int tairgetVendorID = 8260; private static final int ProductID = 1000; private boolean connectUsb() { boolean result = false; switch(checkDeviceInfo()) { case ProductID: result = StairtUSB(); break; } return result; } private int checkDeviceInfo() { deviceFound = null; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); HashMap<String, UsbDevice> deviceList = manager.getDeviceList(); Iterator<UsbDevice> deviceIterator = deviceList.values().iterator(); while (deviceIterator.hasNext()) { UsbDevice device = deviceIterator.next(); if(device.getVendorId()==tairgetVendorID) { deviceFound = device; switch(device.getProductId()) { case ProductID: GetInterface(deviceFound); GetEndpoint(deviceFound); return ProductID; default: Toast.makeText(this, getString(R.string.err_unknow_device), Toast.LENGTH_LONG).show(); break; } return -1; } } return -1; } private void GetInterface(UsbDevice d) { listInterface = new ArrayList<String>(); listUsbInterface = new ArrayList<UsbInterface>(); for(int i=0; i<d.getInterfaceCount(); i++){ UsbInterface usbif = d.getInterface(i); listInterface.add(usbif.toString()); listUsbInterface.add(usbif); } if(d.getInterfaceCount() > 0) { usbInterface = listUsbInterface.get(1); } else usbInterface = null; } private void GetEndpoint(UsbDevice d) { int EndpointCount = usbInterface.getEndpointCount(); listEndPoint = new ArrayList<String>(); listUsbEndpoint = new ArrayList<UsbEndpoint>(); for(int i=0; i<usbInterface.getEndpointCount(); i++) { UsbEndpoint usbEP = usbInterface.getEndpoint(i); listEndPoint.add(usbEP.toString()); listUsbEndpoint.add(usbEP); } // deixair fixo paira TxBlock USB if(EndpointCount > 0) { usbEndpointIN = usbInterface.getEndpoint(0); usbEndpointOUT = usbInterface.getEndpoint(1); } else { usbEndpointIN = null; usbEndpointOUT = null; } } private boolean StairtUSB() { boolean result = false; UsbDevice deviceToRead = deviceFound; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); Boolean permitToRead = manager.hasPermission(deviceToRead); if(permitToRead) { result = OpenDevice(deviceToRead); }else { Toast.makeText(this, getString(R.string.err_no_permission) + permitToRead, Toast.LENGTH_LONG).show(); } return result; } private boolean OpenDevice(UsbDevice device){ boolean forceClaim = true; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); usbDeviceConnection = manager.openDevice(device); if(usbDeviceConnection != null){ usbDeviceConnection.claimInterface(usbInterface, forceClaim); return true; }else{ Toast.makeText(this, getString(R.string.err_no_open_device), Toast.LENGTH_LONG).show(); } return false; } }  UsbInterface usbInterface; UsbEndpoint usbEndpointIN, usbEndpointOUT; UsbDeviceConnection usbDeviceConnection; UsbDevice deviceFound = null; USB USB; ArrayList<String> listInterface; ArrayList<UsbInterface> listUsbInterface; ArrayList<String> listEndPoint; ArrayList<UsbEndpoint> listUsbEndpoint; private static final int tairgetVendorID = 8260; private static final int ProductID = 1000; private boolean connectUsb() { boolean result = false; switch(checkDeviceInfo()) { case ProductID: result = StairtUSB(); break; } return result; } private int checkDeviceInfo() { deviceFound = null; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); HashMap<String, UsbDevice> deviceList = manager.getDeviceList(); Iterator<UsbDevice> deviceIterator = deviceList.values().iterator(); while (deviceIterator.hasNext()) { UsbDevice device = deviceIterator.next(); if(device.getVendorId()==tairgetVendorID) { deviceFound = device; switch(device.getProductId()) { case ProductID: GetInterface(deviceFound); GetEndpoint(deviceFound); return ProductID; default: Toast.makeText(this, getString(R.string.err_unknow_device), Toast.LENGTH_LONG).show(); break; } return -1; } } return -1; } private void GetInterface(UsbDevice d) { listInterface = new ArrayList<String>(); listUsbInterface = new ArrayList<UsbInterface>(); for(int i=0; i<d.getInterfaceCount(); i++){ UsbInterface usbif = d.getInterface(i); listInterface.add(usbif.toString()); listUsbInterface.add(usbif); } if(d.getInterfaceCount() > 0) { usbInterface = listUsbInterface.get(1); } else usbInterface = null; } private void GetEndpoint(UsbDevice d) { int EndpointCount = usbInterface.getEndpointCount(); listEndPoint = new ArrayList<String>(); listUsbEndpoint = new ArrayList<UsbEndpoint>(); for(int i=0; i<usbInterface.getEndpointCount(); i++) { UsbEndpoint usbEP = usbInterface.getEndpoint(i); listEndPoint.add(usbEP.toString()); listUsbEndpoint.add(usbEP); } // deixair fixo paira TxBlock USB if(EndpointCount > 0) { usbEndpointIN = usbInterface.getEndpoint(0); usbEndpointOUT = usbInterface.getEndpoint(1); } else { usbEndpointIN = null; usbEndpointOUT = null; } } private boolean StairtUSB() { boolean result = false; UsbDevice deviceToRead = deviceFound; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); Boolean permitToRead = manager.hasPermission(deviceToRead); if(permitToRead) { result = OpenDevice(deviceToRead); }else { Toast.makeText(this, getString(R.string.err_no_permission) + permitToRead, Toast.LENGTH_LONG).show(); } return result; } private boolean OpenDevice(UsbDevice device){ boolean forceClaim = true; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); usbDeviceConnection = manager.openDevice(device); if(usbDeviceConnection != null){ usbDeviceConnection.claimInterface(usbInterface, forceClaim); return true; }else{ Toast.makeText(this, getString(R.string.err_no_open_device), Toast.LENGTH_LONG).show(); } return false; } }  UsbInterface usbInterface; UsbEndpoint usbEndpointIN, usbEndpointOUT; UsbDeviceConnection usbDeviceConnection; UsbDevice deviceFound = null; USB USB; ArrayList<String> listInterface; ArrayList<UsbInterface> listUsbInterface; ArrayList<String> listEndPoint; ArrayList<UsbEndpoint> listUsbEndpoint; private static final int tairgetVendorID = 8260; private static final int ProductID = 1000; private boolean connectUsb() { boolean result = false; switch(checkDeviceInfo()) { case ProductID: result = StairtUSB(); break; } return result; } private int checkDeviceInfo() { deviceFound = null; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); HashMap<String, UsbDevice> deviceList = manager.getDeviceList(); Iterator<UsbDevice> deviceIterator = deviceList.values().iterator(); while (deviceIterator.hasNext()) { UsbDevice device = deviceIterator.next(); if(device.getVendorId()==tairgetVendorID) { deviceFound = device; switch(device.getProductId()) { case ProductID: GetInterface(deviceFound); GetEndpoint(deviceFound); return ProductID; default: Toast.makeText(this, getString(R.string.err_unknow_device), Toast.LENGTH_LONG).show(); break; } return -1; } } return -1; } private void GetInterface(UsbDevice d) { listInterface = new ArrayList<String>(); listUsbInterface = new ArrayList<UsbInterface>(); for(int i=0; i<d.getInterfaceCount(); i++){ UsbInterface usbif = d.getInterface(i); listInterface.add(usbif.toString()); listUsbInterface.add(usbif); } if(d.getInterfaceCount() > 0) { usbInterface = listUsbInterface.get(1); } else usbInterface = null; } private void GetEndpoint(UsbDevice d) { int EndpointCount = usbInterface.getEndpointCount(); listEndPoint = new ArrayList<String>(); listUsbEndpoint = new ArrayList<UsbEndpoint>(); for(int i=0; i<usbInterface.getEndpointCount(); i++) { UsbEndpoint usbEP = usbInterface.getEndpoint(i); listEndPoint.add(usbEP.toString()); listUsbEndpoint.add(usbEP); } // deixair fixo paira TxBlock USB if(EndpointCount > 0) { usbEndpointIN = usbInterface.getEndpoint(0); usbEndpointOUT = usbInterface.getEndpoint(1); } else { usbEndpointIN = null; usbEndpointOUT = null; } } private boolean StairtUSB() { boolean result = false; UsbDevice deviceToRead = deviceFound; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); Boolean permitToRead = manager.hasPermission(deviceToRead); if(permitToRead) { result = OpenDevice(deviceToRead); }else { Toast.makeText(this, getString(R.string.err_no_permission) + permitToRead, Toast.LENGTH_LONG).show(); } return result; } private boolean OpenDevice(UsbDevice device){ boolean forceClaim = true; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); usbDeviceConnection = manager.openDevice(device); if(usbDeviceConnection != null){ usbDeviceConnection.claimInterface(usbInterface, forceClaim); return true; }else{ Toast.makeText(this, getString(R.string.err_no_open_device), Toast.LENGTH_LONG).show(); } return false; } }  UsbInterface usbInterface; UsbEndpoint usbEndpointIN, usbEndpointOUT; UsbDeviceConnection usbDeviceConnection; UsbDevice deviceFound = null; USB USB; ArrayList<String> listInterface; ArrayList<UsbInterface> listUsbInterface; ArrayList<String> listEndPoint; ArrayList<UsbEndpoint> listUsbEndpoint; private static final int tairgetVendorID = 8260; private static final int ProductID = 1000; private boolean connectUsb() { boolean result = false; switch(checkDeviceInfo()) { case ProductID: result = StairtUSB(); break; } return result; } private int checkDeviceInfo() { deviceFound = null; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); HashMap<String, UsbDevice> deviceList = manager.getDeviceList(); Iterator<UsbDevice> deviceIterator = deviceList.values().iterator(); while (deviceIterator.hasNext()) { UsbDevice device = deviceIterator.next(); if(device.getVendorId()==tairgetVendorID) { deviceFound = device; switch(device.getProductId()) { case ProductID: GetInterface(deviceFound); GetEndpoint(deviceFound); return ProductID; default: Toast.makeText(this, getString(R.string.err_unknow_device), Toast.LENGTH_LONG).show(); break; } return -1; } } return -1; } private void GetInterface(UsbDevice d) { listInterface = new ArrayList<String>(); listUsbInterface = new ArrayList<UsbInterface>(); for(int i=0; i<d.getInterfaceCount(); i++){ UsbInterface usbif = d.getInterface(i); listInterface.add(usbif.toString()); listUsbInterface.add(usbif); } if(d.getInterfaceCount() > 0) { usbInterface = listUsbInterface.get(1); } else usbInterface = null; } private void GetEndpoint(UsbDevice d) { int EndpointCount = usbInterface.getEndpointCount(); listEndPoint = new ArrayList<String>(); listUsbEndpoint = new ArrayList<UsbEndpoint>(); for(int i=0; i<usbInterface.getEndpointCount(); i++) { UsbEndpoint usbEP = usbInterface.getEndpoint(i); listEndPoint.add(usbEP.toString()); listUsbEndpoint.add(usbEP); } // deixair fixo paira TxBlock USB if(EndpointCount > 0) { usbEndpointIN = usbInterface.getEndpoint(0); usbEndpointOUT = usbInterface.getEndpoint(1); } else { usbEndpointIN = null; usbEndpointOUT = null; } } private boolean StairtUSB() { boolean result = false; UsbDevice deviceToRead = deviceFound; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); Boolean permitToRead = manager.hasPermission(deviceToRead); if(permitToRead) { result = OpenDevice(deviceToRead); }else { Toast.makeText(this, getString(R.string.err_no_permission) + permitToRead, Toast.LENGTH_LONG).show(); } return result; } private boolean OpenDevice(UsbDevice device){ boolean forceClaim = true; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); usbDeviceConnection = manager.openDevice(device); if(usbDeviceConnection != null){ usbDeviceConnection.claimInterface(usbInterface, forceClaim); return true; }else{ Toast.makeText(this, getString(R.string.err_no_open_device), Toast.LENGTH_LONG).show(); } return false; } retornair viewdadeiro;  UsbInterface usbInterface; UsbEndpoint usbEndpointIN, usbEndpointOUT; UsbDeviceConnection usbDeviceConnection; UsbDevice deviceFound = null; USB USB; ArrayList<String> listInterface; ArrayList<UsbInterface> listUsbInterface; ArrayList<String> listEndPoint; ArrayList<UsbEndpoint> listUsbEndpoint; private static final int tairgetVendorID = 8260; private static final int ProductID = 1000; private boolean connectUsb() { boolean result = false; switch(checkDeviceInfo()) { case ProductID: result = StairtUSB(); break; } return result; } private int checkDeviceInfo() { deviceFound = null; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); HashMap<String, UsbDevice> deviceList = manager.getDeviceList(); Iterator<UsbDevice> deviceIterator = deviceList.values().iterator(); while (deviceIterator.hasNext()) { UsbDevice device = deviceIterator.next(); if(device.getVendorId()==tairgetVendorID) { deviceFound = device; switch(device.getProductId()) { case ProductID: GetInterface(deviceFound); GetEndpoint(deviceFound); return ProductID; default: Toast.makeText(this, getString(R.string.err_unknow_device), Toast.LENGTH_LONG).show(); break; } return -1; } } return -1; } private void GetInterface(UsbDevice d) { listInterface = new ArrayList<String>(); listUsbInterface = new ArrayList<UsbInterface>(); for(int i=0; i<d.getInterfaceCount(); i++){ UsbInterface usbif = d.getInterface(i); listInterface.add(usbif.toString()); listUsbInterface.add(usbif); } if(d.getInterfaceCount() > 0) { usbInterface = listUsbInterface.get(1); } else usbInterface = null; } private void GetEndpoint(UsbDevice d) { int EndpointCount = usbInterface.getEndpointCount(); listEndPoint = new ArrayList<String>(); listUsbEndpoint = new ArrayList<UsbEndpoint>(); for(int i=0; i<usbInterface.getEndpointCount(); i++) { UsbEndpoint usbEP = usbInterface.getEndpoint(i); listEndPoint.add(usbEP.toString()); listUsbEndpoint.add(usbEP); } // deixair fixo paira TxBlock USB if(EndpointCount > 0) { usbEndpointIN = usbInterface.getEndpoint(0); usbEndpointOUT = usbInterface.getEndpoint(1); } else { usbEndpointIN = null; usbEndpointOUT = null; } } private boolean StairtUSB() { boolean result = false; UsbDevice deviceToRead = deviceFound; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); Boolean permitToRead = manager.hasPermission(deviceToRead); if(permitToRead) { result = OpenDevice(deviceToRead); }else { Toast.makeText(this, getString(R.string.err_no_permission) + permitToRead, Toast.LENGTH_LONG).show(); } return result; } private boolean OpenDevice(UsbDevice device){ boolean forceClaim = true; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); usbDeviceConnection = manager.openDevice(device); if(usbDeviceConnection != null){ usbDeviceConnection.claimInterface(usbInterface, forceClaim); return true; }else{ Toast.makeText(this, getString(R.string.err_no_open_device), Toast.LENGTH_LONG).show(); } return false; } }  UsbInterface usbInterface; UsbEndpoint usbEndpointIN, usbEndpointOUT; UsbDeviceConnection usbDeviceConnection; UsbDevice deviceFound = null; USB USB; ArrayList<String> listInterface; ArrayList<UsbInterface> listUsbInterface; ArrayList<String> listEndPoint; ArrayList<UsbEndpoint> listUsbEndpoint; private static final int tairgetVendorID = 8260; private static final int ProductID = 1000; private boolean connectUsb() { boolean result = false; switch(checkDeviceInfo()) { case ProductID: result = StairtUSB(); break; } return result; } private int checkDeviceInfo() { deviceFound = null; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); HashMap<String, UsbDevice> deviceList = manager.getDeviceList(); Iterator<UsbDevice> deviceIterator = deviceList.values().iterator(); while (deviceIterator.hasNext()) { UsbDevice device = deviceIterator.next(); if(device.getVendorId()==tairgetVendorID) { deviceFound = device; switch(device.getProductId()) { case ProductID: GetInterface(deviceFound); GetEndpoint(deviceFound); return ProductID; default: Toast.makeText(this, getString(R.string.err_unknow_device), Toast.LENGTH_LONG).show(); break; } return -1; } } return -1; } private void GetInterface(UsbDevice d) { listInterface = new ArrayList<String>(); listUsbInterface = new ArrayList<UsbInterface>(); for(int i=0; i<d.getInterfaceCount(); i++){ UsbInterface usbif = d.getInterface(i); listInterface.add(usbif.toString()); listUsbInterface.add(usbif); } if(d.getInterfaceCount() > 0) { usbInterface = listUsbInterface.get(1); } else usbInterface = null; } private void GetEndpoint(UsbDevice d) { int EndpointCount = usbInterface.getEndpointCount(); listEndPoint = new ArrayList<String>(); listUsbEndpoint = new ArrayList<UsbEndpoint>(); for(int i=0; i<usbInterface.getEndpointCount(); i++) { UsbEndpoint usbEP = usbInterface.getEndpoint(i); listEndPoint.add(usbEP.toString()); listUsbEndpoint.add(usbEP); } // deixair fixo paira TxBlock USB if(EndpointCount > 0) { usbEndpointIN = usbInterface.getEndpoint(0); usbEndpointOUT = usbInterface.getEndpoint(1); } else { usbEndpointIN = null; usbEndpointOUT = null; } } private boolean StairtUSB() { boolean result = false; UsbDevice deviceToRead = deviceFound; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); Boolean permitToRead = manager.hasPermission(deviceToRead); if(permitToRead) { result = OpenDevice(deviceToRead); }else { Toast.makeText(this, getString(R.string.err_no_permission) + permitToRead, Toast.LENGTH_LONG).show(); } return result; } private boolean OpenDevice(UsbDevice device){ boolean forceClaim = true; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); usbDeviceConnection = manager.openDevice(device); if(usbDeviceConnection != null){ usbDeviceConnection.claimInterface(usbInterface, forceClaim); return true; }else{ Toast.makeText(this, getString(R.string.err_no_open_device), Toast.LENGTH_LONG).show(); } return false; } retornair falso;  UsbInterface usbInterface; UsbEndpoint usbEndpointIN, usbEndpointOUT; UsbDeviceConnection usbDeviceConnection; UsbDevice deviceFound = null; USB USB; ArrayList<String> listInterface; ArrayList<UsbInterface> listUsbInterface; ArrayList<String> listEndPoint; ArrayList<UsbEndpoint> listUsbEndpoint; private static final int tairgetVendorID = 8260; private static final int ProductID = 1000; private boolean connectUsb() { boolean result = false; switch(checkDeviceInfo()) { case ProductID: result = StairtUSB(); break; } return result; } private int checkDeviceInfo() { deviceFound = null; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); HashMap<String, UsbDevice> deviceList = manager.getDeviceList(); Iterator<UsbDevice> deviceIterator = deviceList.values().iterator(); while (deviceIterator.hasNext()) { UsbDevice device = deviceIterator.next(); if(device.getVendorId()==tairgetVendorID) { deviceFound = device; switch(device.getProductId()) { case ProductID: GetInterface(deviceFound); GetEndpoint(deviceFound); return ProductID; default: Toast.makeText(this, getString(R.string.err_unknow_device), Toast.LENGTH_LONG).show(); break; } return -1; } } return -1; } private void GetInterface(UsbDevice d) { listInterface = new ArrayList<String>(); listUsbInterface = new ArrayList<UsbInterface>(); for(int i=0; i<d.getInterfaceCount(); i++){ UsbInterface usbif = d.getInterface(i); listInterface.add(usbif.toString()); listUsbInterface.add(usbif); } if(d.getInterfaceCount() > 0) { usbInterface = listUsbInterface.get(1); } else usbInterface = null; } private void GetEndpoint(UsbDevice d) { int EndpointCount = usbInterface.getEndpointCount(); listEndPoint = new ArrayList<String>(); listUsbEndpoint = new ArrayList<UsbEndpoint>(); for(int i=0; i<usbInterface.getEndpointCount(); i++) { UsbEndpoint usbEP = usbInterface.getEndpoint(i); listEndPoint.add(usbEP.toString()); listUsbEndpoint.add(usbEP); } // deixair fixo paira TxBlock USB if(EndpointCount > 0) { usbEndpointIN = usbInterface.getEndpoint(0); usbEndpointOUT = usbInterface.getEndpoint(1); } else { usbEndpointIN = null; usbEndpointOUT = null; } } private boolean StairtUSB() { boolean result = false; UsbDevice deviceToRead = deviceFound; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); Boolean permitToRead = manager.hasPermission(deviceToRead); if(permitToRead) { result = OpenDevice(deviceToRead); }else { Toast.makeText(this, getString(R.string.err_no_permission) + permitToRead, Toast.LENGTH_LONG).show(); } return result; } private boolean OpenDevice(UsbDevice device){ boolean forceClaim = true; UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); usbDeviceConnection = manager.openDevice(device); if(usbDeviceConnection != null){ usbDeviceConnection.claimInterface(usbInterface, forceClaim); return true; }else{ Toast.makeText(this, getString(R.string.err_no_open_device), Toast.LENGTH_LONG).show(); } return false; } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.