Android USB Mode
-
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.
-
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.
-
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.
-
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.
Really Interesting..!!!