Android UsbManager - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android UsbManager class.

This code example shows how to use the following methods: openAccessory
       super.onDestroy(); 
    } 
 
    private void openAccessory(UsbAccessory accessory) {
        Log.d(TAG, "openAccessory: " + accessory);
        mFileDescriptor = mUsbManager.openAccessory(accessory);
        if (mFileDescriptor != null) {
            FileDescriptor fd = mFileDescriptor.getFileDescriptor();
            mInputStream = new FileInputStream(fd);
            mOutputStream = new FileOutputStream(fd);
            Thread thread = new Thread(null, this, "AccessoryChat");
            thread.start();
            Log.d(TAG, "openAccessory succeeded");
        } else { 
            Log.d(TAG, "openAccessory fail");
        } 
    } 
 
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        if (actionId == EditorInfo.IME_ACTION_DONE && mOutputStream != null) {
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getDeviceList, openDevice
        manager = (UsbManager) context.getSystemService(Service.USB_SERVICE);
    } 
 
    @SuppressWarnings("UnusedDeclaration") 
    public static UsbDeviceConnection openDevice(String path) {
        UsbDevice device = manager.getDeviceList().get(path);
        if (device == null) return null;
        return manager.openDevice(device);
    } 
} 
Full Snippet Info
6
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getAccessoryList, hasPermission
            //       Note however that the IDE still thinks that Gingerbread is required 
            //       thus the use of the `@TargetAPi(12)` above. 
            Class.forName("android.hardware.usb.UsbManager");
 
            UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
            UsbAccessory[] accessoryList = manager.getAccessoryList();
 
            // Note: The permissions check here is because sometimes we end up 
            //       with spurious accessories (e.g. ^B in the device description etc) 
            //       and presumably it also stops problems if an accessory is connected 
            //       when we're open. 
            result = ((accessoryList != null) && (manager.hasPermission(accessoryList[0])));
        } catch (ClassNotFoundException e) {
            Log.d(this.getClass().getSimpleName(),
                    "No USB accessory support, 'android.hardware.usb.UsbManager' not found."); 
        } 
 
        return result;
    } 
 
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: openAccessory
       super.onDestroy(); 
    } 
 
    private void openAccessory(UsbAccessory accessory) {
        Log.d(TAG, "openAccessory: " + accessory);
        mFileDescriptor = mUsbManager.openAccessory(accessory);
        if (mFileDescriptor != null) {
            FileDescriptor fd = mFileDescriptor.getFileDescriptor();
            mInputStream = new FileInputStream(fd);
            mOutputStream = new FileOutputStream(fd);
            Thread thread = new Thread(null, this, "AccessoryChat");
            thread.start();
            Log.d(TAG, "openAccessory succeeded");
        } else { 
            Log.d(TAG, "openAccessory fail");
        } 
    } 
 
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        if (actionId == EditorInfo.IME_ACTION_DONE && mOutputStream != null) {
Full Snippet Info
6
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: openDevice
            return; 
        } 
        mDevice = device;
        mEndpointIntr = ep;
        if (device != null) {
            UsbDeviceConnection connection = mUsbManager.openDevice(device);
            if (connection != null && connection.claimInterface(intf, true)) {
                Log.d(TAG, "open SUCCESS");
                mConnection = connection;
                Thread thread = new Thread(this);
                thread.start();
 
            } else { 
                Log.d(TAG, "open FAIL");
                mConnection = null;
            } 
         } 
    } 
 
    private void sendCommand(int control) {
Full Snippet Info
6
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE

Related Android UsbManager Questions & Answers:

See Code Examples for Android UsbManager Methods: