Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- UsbManager usbManager = (UsbManager) getContext().getSystemService(Context.USB_SERVICE);
- PendingIntent mPermissionIntent = PendingIntent.getBroadcast(getContext(), 0, new Intent(ACTION_USB_PERMISSION), 0);
- IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
- getContext().registerReceiver(usbReceiver, filter);
- HashMap<String, UsbDevice> deviceList = usbManager.getDeviceList();
- Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
- while (deviceIterator.hasNext()) {
- final UsbDevice device = deviceIterator.next();
- if (device.getVendorId() == 1659 && device.getProductId() == 8963) {
- this.device = device;
- usbManager.requestPermission(device, mPermissionIntent);
- break;
- }
- final UsbConnector.CallbackListener listener = new UsbConnector.CallbackListener() {
- @Override
- public void onStatusChanged(UsbConnector.Status newStatus) {
- Toast.makeText(getContext(), "Status" + newStatus, Toast.LENGTH_SHORT).show();
- }
- @Override
- public void onScanCompleted(String result) {
- Toast.makeText(getContext(), "Result" + result, Toast.LENGTH_SHORT).show();
- }
- };
- UsbConnector connector = new UsbConnector(getContext(), device, listener);
- if (device != null) {
- connector.run();
- connector.send(pal);
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- byte[] received = connector.receive(36);
- if (received == null) {
- Toast.makeText(getContext(), "Błąd inicjalizacji skanera", Toast.LENGTH_SHORT).show();
- }
- if (received != null) {
- //
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement