Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Mobile Development
  3. Android
  4. Android USB Mode

Android USB Mode

Scheduled Pinned Locked Moved Android
androidcomhardware
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sarita S
    wrote on last edited by
    #1

    I have following code for detection of attached USB. { UsbManager manager; @Override public void onReceive(Context context, Intent intent) { Toast.makeText(context, "Broadcast Receiver", Toast.LENGTH_SHORT) .show(); onNewIntent(intent,context); } private void onNewIntent(Intent intent, Context context) { String intentAction = intent.getAction(); Toast.makeText(context,"Action :" + intentAction, Toast.LENGTH_SHORT).show(); if(intentAction.equalsIgnoreCase("android.hardware.usb.action.USB_DEVICE_ATTACHED")) { Toast.makeText(context,"Dveice Attached", Toast.LENGTH_SHORT).show(); handleDevice(intent,context); } else if(intentAction.equalsIgnoreCase("android.hardware.usb.action.USB_DEVICE_ATTACHED")) { Toast.makeText(context,"Dveice Detached", Toast.LENGTH_SHORT).show(); } else { } } private void handleDevice(Intent intent,Context context) { manager = (UsbManager) context.getSystemService(UsbManager.EXTRA_DEVICE); HashMap list = manager.getDeviceList(); Iterator it = list.values().iterator(); while(it.hasNext()) { UsbDevice device = it.next(); openDevice(device); } } private void openDevice(UsbDevice device) { UsbDeviceConnection connection = manager.openDevice(device); int fd = connection.getFileDescriptor(); Log.d("Fd :"+fd,"Text"); } not firing the USB_DEVICE_ATTACHED event.

    L S U 3 Replies Last reply
    0
    • S Sarita S

      I have following code for detection of attached USB. { UsbManager manager; @Override public void onReceive(Context context, Intent intent) { Toast.makeText(context, "Broadcast Receiver", Toast.LENGTH_SHORT) .show(); onNewIntent(intent,context); } private void onNewIntent(Intent intent, Context context) { String intentAction = intent.getAction(); Toast.makeText(context,"Action :" + intentAction, Toast.LENGTH_SHORT).show(); if(intentAction.equalsIgnoreCase("android.hardware.usb.action.USB_DEVICE_ATTACHED")) { Toast.makeText(context,"Dveice Attached", Toast.LENGTH_SHORT).show(); handleDevice(intent,context); } else if(intentAction.equalsIgnoreCase("android.hardware.usb.action.USB_DEVICE_ATTACHED")) { Toast.makeText(context,"Dveice Detached", Toast.LENGTH_SHORT).show(); } else { } } private void handleDevice(Intent intent,Context context) { manager = (UsbManager) context.getSystemService(UsbManager.EXTRA_DEVICE); HashMap list = manager.getDeviceList(); Iterator it = list.values().iterator(); while(it.hasNext()) { UsbDevice device = it.next(); openDevice(device); } } private void openDevice(UsbDevice device) { UsbDeviceConnection connection = manager.openDevice(device); int fd = connection.getFileDescriptor(); Log.d("Fd :"+fd,"Text"); } not firing the USB_DEVICE_ATTACHED event.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      See http://stackoverflow.com/questions/6163856/usb-device-attached-intent-not-firing[^].

      1 Reply Last reply
      0
      • S Sarita S

        I have following code for detection of attached USB. { UsbManager manager; @Override public void onReceive(Context context, Intent intent) { Toast.makeText(context, "Broadcast Receiver", Toast.LENGTH_SHORT) .show(); onNewIntent(intent,context); } private void onNewIntent(Intent intent, Context context) { String intentAction = intent.getAction(); Toast.makeText(context,"Action :" + intentAction, Toast.LENGTH_SHORT).show(); if(intentAction.equalsIgnoreCase("android.hardware.usb.action.USB_DEVICE_ATTACHED")) { Toast.makeText(context,"Dveice Attached", Toast.LENGTH_SHORT).show(); handleDevice(intent,context); } else if(intentAction.equalsIgnoreCase("android.hardware.usb.action.USB_DEVICE_ATTACHED")) { Toast.makeText(context,"Dveice Detached", Toast.LENGTH_SHORT).show(); } else { } } private void handleDevice(Intent intent,Context context) { manager = (UsbManager) context.getSystemService(UsbManager.EXTRA_DEVICE); HashMap list = manager.getDeviceList(); Iterator it = list.values().iterator(); while(it.hasNext()) { UsbDevice device = it.next(); openDevice(device); } } private void openDevice(UsbDevice device) { UsbDeviceConnection connection = manager.openDevice(device); int fd = connection.getFileDescriptor(); Log.d("Fd :"+fd,"Text"); } not firing the USB_DEVICE_ATTACHED event.

        S Offline
        S Offline
        Sarita S
        wrote on last edited by
        #3

        You need to handle device attached event itself in launcher activity.On the other hand If you want to handle detached event you need to have a broadcast receiver.

        1 Reply Last reply
        0
        • S Sarita S

          I have following code for detection of attached USB. { UsbManager manager; @Override public void onReceive(Context context, Intent intent) { Toast.makeText(context, "Broadcast Receiver", Toast.LENGTH_SHORT) .show(); onNewIntent(intent,context); } private void onNewIntent(Intent intent, Context context) { String intentAction = intent.getAction(); Toast.makeText(context,"Action :" + intentAction, Toast.LENGTH_SHORT).show(); if(intentAction.equalsIgnoreCase("android.hardware.usb.action.USB_DEVICE_ATTACHED")) { Toast.makeText(context,"Dveice Attached", Toast.LENGTH_SHORT).show(); handleDevice(intent,context); } else if(intentAction.equalsIgnoreCase("android.hardware.usb.action.USB_DEVICE_ATTACHED")) { Toast.makeText(context,"Dveice Detached", Toast.LENGTH_SHORT).show(); } else { } } private void handleDevice(Intent intent,Context context) { manager = (UsbManager) context.getSystemService(UsbManager.EXTRA_DEVICE); HashMap list = manager.getDeviceList(); Iterator it = list.values().iterator(); while(it.hasNext()) { UsbDevice device = it.next(); openDevice(device); } } private void openDevice(UsbDevice device) { UsbDeviceConnection connection = manager.openDevice(device); int fd = connection.getFileDescriptor(); Log.d("Fd :"+fd,"Text"); } not firing the USB_DEVICE_ATTACHED event.

          U Offline
          U Offline
          User 11697664
          wrote on last edited by
          #4

          Really Interesting..!!!

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups