Code example for FragmentActivity

Methods: onDestroy, unregisterReceiver

0
        closeAccessory(); 
    } 
 
    @Override 
    public void onDestroy() { 
        unregisterReceiver(mUsbReceiver);
        super.onDestroy(); 
    } 
 
    private void openAccessory(UsbAccessory accessory) {
        mFileDescriptor = mUsbManager.openAccessory(accessory);
        if (mFileDescriptor != null) {
            mAccessory = accessory;
            FileDescriptor fd = mFileDescriptor.getFileDescriptor();
            mInputStream = new FileInputStream(fd);
            mOutputStream = new FileOutputStream(fd);
            Log.d(TAG, "accessory opened");
            showControls(); 
        } else { 
            Log.d(TAG, "accessory open fail");
            hideControls();