Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public void onResume() {
- super.onResume();
- setFilters(); // Start listening notifications from UsbService
- startService(UsbService.class, usbConnection, null); // Start UsbService(if it was not started before) and Bind it
- }
- private void startService(Class<?> service, ServiceConnection serviceConnection, Bundle extras) {
- if (!UsbService.SERVICE_CONNECTED) {
- Intent startService = new Intent(this, service);
- if (extras != null && !extras.isEmpty()) {
- Set<String> keys = extras.keySet();
- for (String key : keys) {
- String extra = extras.getString(key);
- startService.putExtra(key, extra);
- }
- }
- startService(startService);
- }
- Intent bindingIntent = new Intent(this, service);
- bindService(bindingIntent, serviceConnection, Context.BIND_AUTO_CREATE);
- statusUSB = true;
- }
- private void setFilters() {
- IntentFilter filter = new IntentFilter();
- filter.addAction(UsbService.ACTION_USB_PERMISSION_GRANTED);
- filter.addAction(ACTION_NO_USB);
- filter.addAction(UsbService.ACTION_USB_DISCONNECTED);
- filter.addAction(UsbService.ACTION_USB_NOT_SUPPORTED);
- filter.addAction(UsbService.ACTION_USB_PERMISSION_NOT_GRANTED);
- registerReceiver(mUsbReceiver, filter);
- }
Add Comment
Please, Sign In to add comment