Guest User

Untitled

a guest
Dec 13th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. @Override
  2. public void onResume() {
  3. super.onResume();
  4. setFilters(); // Start listening notifications from UsbService
  5. startService(UsbService.class, usbConnection, null); // Start UsbService(if it was not started before) and Bind it
  6. }
  7.  
  8. private void startService(Class<?> service, ServiceConnection serviceConnection, Bundle extras) {
  9. if (!UsbService.SERVICE_CONNECTED) {
  10. Intent startService = new Intent(this, service);
  11. if (extras != null && !extras.isEmpty()) {
  12. Set<String> keys = extras.keySet();
  13. for (String key : keys) {
  14. String extra = extras.getString(key);
  15. startService.putExtra(key, extra);
  16. }
  17. }
  18. startService(startService);
  19. }
  20. Intent bindingIntent = new Intent(this, service);
  21. bindService(bindingIntent, serviceConnection, Context.BIND_AUTO_CREATE);
  22. statusUSB = true;
  23. }
  24.  
  25. private void setFilters() {
  26. IntentFilter filter = new IntentFilter();
  27. filter.addAction(UsbService.ACTION_USB_PERMISSION_GRANTED);
  28. filter.addAction(ACTION_NO_USB);
  29. filter.addAction(UsbService.ACTION_USB_DISCONNECTED);
  30. filter.addAction(UsbService.ACTION_USB_NOT_SUPPORTED);
  31. filter.addAction(UsbService.ACTION_USB_PERMISSION_NOT_GRANTED);
  32. registerReceiver(mUsbReceiver, filter);
  33. }
Add Comment
Please, Sign In to add comment