Example usage for android.hardware.usb UsbManager ACTION_USB_DEVICE_DETACHED

List of usage examples for android.hardware.usb UsbManager ACTION_USB_DEVICE_DETACHED

Introduction

In this page you can find the example usage for android.hardware.usb UsbManager ACTION_USB_DEVICE_DETACHED.

Prototype

String ACTION_USB_DEVICE_DETACHED

To view the source code for android.hardware.usb UsbManager ACTION_USB_DEVICE_DETACHED.

Click Source Link

Document

Broadcast Action: A broadcast for USB device detached event.

Usage

From source file:me.spadival.podmode.PodModeService.java

@Override
public void onCreate() {

    IntentFilter usbFilter = new IntentFilter();
    usbFilter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
    usbFilter.addAction(UsbManager.ACTION_USB_ACCESSORY_DETACHED);
    registerReceiver(mUsbReceiver, usbFilter);
    // mProvider = RemoteMetadataProvider.getInstance(this);

    // mProvider.setOnMetadataChangeListener(mMetadataListner);
    // mProvider.acquireRemoteControls();
    LocalBroadcastManager bManager = LocalBroadcastManager.getInstance(this);
    IntentFilter notifyFilter = new IntentFilter();
    notifyFilter.addAction(NOTIFYACTION);
    bManager.registerReceiver(mNotifyReceiver, notifyFilter);

    mSerialHost = new FTDriver((UsbManager) getSystemService(Context.USB_SERVICE));

    mSerialDevice = new FT311UARTInterface(this, null);

    // Get the local Bluetooth adapter
    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    // Get a set of currently paired devices
    Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();

    mBluetoothDevice = null;// w ww  . j a v  a 2s. c o m

    /*   // If there are paired devices, add each one to the ArrayAdapter
       if (pairedDevices.size() > 0) {
          for (BluetoothDevice device : pairedDevices) {
    if (device.getName().equals("PodModeBT"))
       mBluetoothDevice = device;
          }
       }
            
       if (mBluetoothDevice != null) {
          mBTDevice = new BluetoothSerialService(this, mHandler);
          mBTDevice.connect(mBluetoothDevice);
       } */

    // Create the Wifi lock (this does not acquire the lock, this just
    // creates it)
    mWifiLock = ((WifiManager) getSystemService(Context.WIFI_SERVICE))
            .createWifiLock(WifiManager.WIFI_MODE_FULL, "mylock");

    mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE);

    // Create the retriever and start an asynchronous task that will prepare
    // it.

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

    mRetriever = new MusicRetriever(getContentResolver(), getApplicationContext(), true, prefs);

    // mRetriever.switchToMainPlaylist();

    prefs.registerOnSharedPreferenceChangeListener((OnSharedPreferenceChangeListener) this);

    mNowPlaying = prefs.getInt("nowplaying", 0);

    String mBaudrate = prefs.getString("baud_rate", "57600");

    if (mBaudrate.equals("57600"))
        mSerialBaudRate = FTDriver.BAUD57600;
    else if (mBaudrate.equals("38400"))
        mSerialBaudRate = FTDriver.BAUD38400;
    else if (mBaudrate.equals("19200"))
        mSerialBaudRate = FTDriver.BAUD19200;

    (new PrepareMusicRetrieverTask(mRetriever, this)).execute();

    // create the Audio Focus Helper, if the Audio Focus feature is
    // available (SDK 8 or above)
    if (android.os.Build.VERSION.SDK_INT >= 8)
        mAudioFocusHelper = new AudioFocusHelper(getApplicationContext(), this);
    else
        mAudioFocus = AudioFocus.Focused; // no focus feature, so we always
    // "have" audio focus

    boolean wakeLockPreferred = prefs.getBoolean("wakelock", false);

    if (podWakeLock == null && wakeLockPreferred) {
        PowerManager powerMgr = (PowerManager) getSystemService(Context.POWER_SERVICE);
        podWakeLock = powerMgr.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, WAKETAG);
        podWakeLock.acquire();
    }

    PackageManager pxm = getPackageManager();
    Intent mediaIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);

    List<ResolveInfo> mAppsInfo = pxm.queryBroadcastReceivers(mediaIntent, 0);

    mSimpleRemoteApp = prefs.getString("selectapp", null);
    mAdvancedRemoteApp = prefs.getString("selectadvancedapp", PACKAGENAME);

    // Make sure App preferences are still valid and Apps haven't been
    // uninstalled.

    if (mAppsInfo.size() > 0) {

        CharSequence[] entryValues = new CharSequence[mAppsInfo.size()];
        CharSequence[] advEntryValues = new CharSequence[mAppsInfo.size() + 1];

        advEntryValues[0] = PACKAGENAME;

        int i = 0;
        for (ResolveInfo info : mAppsInfo) {
            entryValues[i] = (String) info.activityInfo.packageName;
            advEntryValues[i + 1] = (String) info.activityInfo.packageName;

            i++;
        }

        boolean entryFound = false;

        if (mSimpleRemoteApp != null) {
            for (i = 0; i < entryValues.length; i++) {
                if (mSimpleRemoteApp.equals(entryValues[i])) {
                    entryFound = true;
                }
            }
        }

        if (!entryFound) {
            SharedPreferences.Editor editor = prefs.edit();
            editor.putString("selectapp", (String) entryValues[0]);
            editor.commit();
            mSimpleRemoteApp = (String) entryValues[0];
        }

        entryFound = false;

        if (mAdvancedRemoteApp != null) {
            for (i = 0; i < advEntryValues.length; i++) {
                if (mAdvancedRemoteApp.equals(advEntryValues[i])) {
                    entryFound = true;
                }
            }
        }

        if (!entryFound) {
            SharedPreferences.Editor editor = prefs.edit();
            editor.putString("selectadvancedapp", (String) advEntryValues[0]);
            editor.commit();
            mAdvancedRemoteApp = (String) advEntryValues[0];

        }
    } else {
        SharedPreferences.Editor editor = prefs.edit();
        editor.putString("selectadvancedapp", PACKAGENAME);
        editor.commit();
        mAdvancedRemoteApp = PACKAGENAME;
    }

    mAccessoryName = prefs.getString("accessoryName", null);
    mAccessoryMnf = prefs.getString("accessoryMnf", null);
    mAccessoryModel = prefs.getString("accessoryModel", null);

}

From source file:com.example.nfcreaderorigin.MainActivity.java

/** Called when the activity is first created. */
@Override/* w w  w .j a va 2  s. c  o  m*/
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    setBlockNumber();
    // Get USB manager
    mManager = (UsbManager) getSystemService(Context.USB_SERVICE);

    // Initialize reader
    mReader = new Reader(mManager);
    mReader.setOnStateChangeListener(new OnStateChangeListener() {

        @Override
        public void onStateChange(int slotNum, int prevState, int currState) {

            if (prevState < Reader.CARD_UNKNOWN || prevState > Reader.CARD_SPECIFIC) {
                prevState = Reader.CARD_UNKNOWN;
            }

            if (currState < Reader.CARD_UNKNOWN || currState > Reader.CARD_SPECIFIC) {
                currState = Reader.CARD_UNKNOWN;
            }

            // Create output string
            final String outputString = "Slot " + slotNum + ": " + stateStrings[prevState] + " -> "
                    + stateStrings[currState];
            final String state = stateStrings[currState];

            // Show output
            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    logMsg(outputString);
                    if (state.equals("Present")) {
                        mAuthenticateRead = false;
                        if (mReadMode) {
                            setBlockNumber();
                            try {

                                mTaskReadStart = false;
                                mTaskStart = false;
                                mTaskWriteStart = false;

                                TimeRead = 0;
                                TimeWrite = 0;
                                timeEnd = 0;
                                initStart = 0;
                                nowRead = 0;
                                nowWrite = 0;
                                nowStart = 0;

                                mBlockAuthen = true;
                                mReadMode = true;
                                mWriteMode = false;

                                System.gc();

                                reader();

                            } catch (Exception e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }

                        }

                    }
                }
            });
        }
    });

    // Register receiver for USB permission
    mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
    IntentFilter filter = new IntentFilter();
    filter.addAction(ACTION_USB_PERMISSION);
    filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
    registerReceiver(mReceiver, filter);

    sdf = new SimpleDateFormat("mm:ss.SSS");

    mResponseTextView = (TextView) findViewById(R.id.main_text_view_response);
    mResponseTextView.setMovementMethod(new ScrollingMovementMethod());
    mResponseTextView.setMaxLines(MAX_LINES);
    mResponseTextView.setText("");

    mTextType = (TextView) findViewById(R.id.textType);
    mReadTime = (TextView) findViewById(R.id.textViewReadSet);
    mWriteTime = (TextView) findViewById(R.id.textViewWriteSet);
    mEndTime = (TextView) findViewById(R.id.textViewEndSet);

    mWriteType = (EditText) findViewById(R.id.EditText_writeDataType);
    mQty = (EditText) findViewById(R.id.QTY);

    formatter = new DecimalFormat("###,###,###.##");

    mWriteDataBalanceEditText = (EditText) findViewById(R.id.EditText_writeDataBalance);
    mWriteDataIdEditText = (EditText) findViewById(R.id.EditText_writeDataId);

    mTextMode = (TextView) findViewById(R.id.textMode);
    mTextBalance = (TextView) findViewById(R.id.BALANCE);

    mTextId = (TextView) findViewById(R.id.textId);
    // Initialize reader spinner

    for (UsbDevice device : mManager.getDeviceList().values()) {
        if (mReader.isSupported(device)) {
            mReaderAdapterX = device.getDeviceName().toString();
        }
    }
    // Initialize open button
    mOpenButton = (Button) findViewById(R.id.btnStart);
    mOpenButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            getDevices();
            // Disable open button
            mOpenButton.setEnabled(false);

        }
    });

    // Initialize close button
    mCloseButton = (Button) findViewById(R.id.btnStop);
    mCloseButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            // Disable buttons

            mOpenButton.setEnabled(false);
            // Clear slot items

            // Close reader
            logMsg("Closing reader...");
            new CloseTask().execute();
        }
    });

    mWriteData = (Button) findViewById(R.id.btnWrite);
    mWriteData.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (mAuthenticateRead == true) {
                mBlockWrite = true;
                setBlockNumber();
                mReadMode = false;
                mWriteMode = true;
                mTextMode.setText("- W R I T E -");
                //               mReadData.setVisibility(View.VISIBLE);
                //               mWriteData.setVisibility(View.GONE);
                try {
                    writer();
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            } else {
                Toast.makeText(getApplicationContext(), "Please Authenticate first", Toast.LENGTH_SHORT).show();
            }

        }
    });

    mReadData = (Button) findViewById(R.id.btnRead);
    mReadData.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            mBlockAuthen = true;
            setBlockNumber();
            mReadMode = true;
            mWriteMode = false;
            mTextMode.setText("- R E A D -");
            //            mReadData.setVisibility(View.GONE);
            //            mWriteData.setVisibility(View.VISIBLE);

        }
    });

    // PIN verification command (ACOS3)
    byte[] pinVerifyData = { (byte) 0x80, 0x20, 0x06, 0x00, 0x08, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
            (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };

    // Initialize PIN verify structure (ACOS3)
    mPinVerify.setTimeOut(0);
    mPinVerify.setTimeOut2(0);
    mPinVerify.setFormatString(0);
    mPinVerify.setPinBlockString(0x08);
    mPinVerify.setPinLengthFormat(0);
    mPinVerify.setPinMaxExtraDigit(0x0408);
    mPinVerify.setEntryValidationCondition(0x03);
    mPinVerify.setNumberMessage(0x01);
    mPinVerify.setLangId(0x0409);
    mPinVerify.setMsgIndex(0);
    mPinVerify.setTeoPrologue(0, 0);
    mPinVerify.setTeoPrologue(1, 0);
    mPinVerify.setTeoPrologue(2, 0);
    mPinVerify.setData(pinVerifyData, pinVerifyData.length);

    // PIN modification command (ACOS3)
    byte[] pinModifyData = { (byte) 0x80, 0x24, 0x00, 0x00, 0x08, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
            (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };

    // Initialize PIN modify structure (ACOS3)
    mPinModify.setTimeOut(0);
    mPinModify.setTimeOut2(0);
    mPinModify.setFormatString(0);
    mPinModify.setPinBlockString(0x08);
    mPinModify.setPinLengthFormat(0);
    mPinModify.setInsertionOffsetOld(0);
    mPinModify.setInsertionOffsetNew(0);
    mPinModify.setPinMaxExtraDigit(0x0408);
    mPinModify.setConfirmPin(0x01);
    mPinModify.setEntryValidationCondition(0x03);
    mPinModify.setNumberMessage(0x02);
    mPinModify.setLangId(0x0409);
    mPinModify.setMsgIndex1(0);
    mPinModify.setMsgIndex2(0x01);
    mPinModify.setMsgIndex3(0);
    mPinModify.setTeoPrologue(0, 0);
    mPinModify.setTeoPrologue(1, 0);
    mPinModify.setTeoPrologue(2, 0);
    mPinModify.setData(pinModifyData, pinModifyData.length);

    // Initialize read key option
    mReadKeyOption.setTimeOut(0);
    mReadKeyOption.setPinMaxExtraDigit(0x0408);
    mReadKeyOption.setKeyReturnCondition(0x01);
    mReadKeyOption.setEchoLcdStartPosition(0);
    mReadKeyOption.setEchoLcdMode(0x01);

    // Disable buttons
    //      mCloseButton.setEnabled(false);
    //      mControlButton.setEnabled(false);

    // Hide input window
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}

From source file:org.broeuschmeul.android.gps.usb.provider.driver.USBGpsManager.java

/**
 * Enables the USB GPS Provider.//  ww w .j av a 2 s . co  m
 *
 * @return
 */
public synchronized boolean enable() {
    IntentFilter permissionFilter = new IntentFilter(ACTION_USB_PERMISSION);
    permissionFilter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
    notificationManager.cancel(R.string.service_closed_because_connection_problem_notification_title);

    if (!enabled) {
        log("enabling USB GPS manager");

        if (!isMockLocationEnabled()) {
            if (BuildConfig.DEBUG || debug)
                Log.e(LOG_TAG, "Mock location provider OFF");
            disable(R.string.msg_mock_location_disabled);
            return this.enabled;

        } else if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(callingService,
                Manifest.permission.ACCESS_FINE_LOCATION)) {
            if (BuildConfig.DEBUG || debug)
                Log.e(LOG_TAG, "No location permission given");
            disable(R.string.msg_no_location_permission);
            return this.enabled;

        } else {
            gpsDev = getDeviceFromAttached();

            // This thread will be run by the executor at a delay of 1 second, and will be
            // run again if the read thread dies. It will run until maximum number of retries
            // is exceeded
            Runnable connectThread = new Runnable() {
                @Override
                public void run() {
                    try {
                        debugLog("Starting connect thread");
                        connected = false;
                        gpsDev = getDeviceFromAttached();

                        if (nbRetriesRemaining > 0) {
                            if (connectedGps != null) {
                                connectedGps.close();
                            }

                            if (gpsDev != null) {
                                debugLog("GPS device: " + gpsDev.getDeviceName());

                                PendingIntent permissionIntent = PendingIntent.getBroadcast(callingService, 0,
                                        new Intent(ACTION_USB_PERMISSION), 0);
                                UsbDevice device = gpsDev;

                                if (device != null && usbManager.hasPermission(device)) {
                                    debugLog("We have permission, good!");
                                    openConnection(device);

                                } else if (device != null) {
                                    debugLog("We don't have permission, so requesting...");
                                    usbManager.requestPermission(device, permissionIntent);

                                } else {
                                    if (BuildConfig.DEBUG || debug)
                                        Log.e(LOG_TAG, "Error while establishing connection: no device - "
                                                + gpsVendorId + ": " + gpsProductId);
                                    disable(R.string.msg_usb_provider_device_not_connected);
                                }
                            } else {
                                if (BuildConfig.DEBUG || debug)
                                    Log.e(LOG_TAG, "Device not connected");
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    } finally {
                        nbRetriesRemaining--;
                        if (!connected) {
                            disableIfNeeded();
                        }
                    }

                }
            };

            if (gpsDev != null) {
                this.enabled = true;
                callingService.registerReceiver(permissionAndDetachReceiver, permissionFilter);

                debugLog("USB GPS manager enabled");

                notificationPool = Executors.newSingleThreadExecutor();
                debugLog("starting connection and reading thread");
                connectionAndReadingPool = Executors.newSingleThreadScheduledExecutor();

                debugLog("starting connection to socket task");
                connectionAndReadingPool.scheduleWithFixedDelay(connectThread, 1000, 1000,
                        TimeUnit.MILLISECONDS);

                if (sirfGps) {
                    enableSirfConfig(sharedPreferences);
                }
            }
        }

        if (!this.enabled) {
            if (BuildConfig.DEBUG || debug)
                Log.e(LOG_TAG, "Error while establishing connection: no device");
            disable(R.string.msg_usb_provider_device_not_connected);
        }
    }
    return this.enabled;
}

From source file:com.igniva.filemanager.activities.MainActivity.java

@Override
public void onResume() {
    super.onResume();
    if (materialDialog != null && !materialDialog.isShowing()) {
        materialDialog.show();//from w  w w .ja v a2s.c o m
        materialDialog = null;
    }
    IntentFilter newFilter = new IntentFilter();
    newFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);
    newFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
    newFilter.addDataScheme(ContentResolver.SCHEME_FILE);
    registerReceiver(mainActivityHelper.mNotificationReceiver, newFilter);
    registerReceiver(receiver2, new IntentFilter("general_communications"));
    if (getSupportFragmentManager().findFragmentById(R.id.content_frame).getClass().getName()
            .contains("TabFragment")) {

        floatingActionButton.setVisibility(View.VISIBLE);
        floatingActionButton.showMenuButton(false);
    } else {

        floatingActionButton.setVisibility(View.INVISIBLE);
        floatingActionButton.hideMenuButton(false);
    }

    // Registering intent filter for OTG
    IntentFilter otgFilter = new IntentFilter();
    otgFilter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
    otgFilter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
}

From source file:com.amaze.carbonfilemanager.activities.MainActivity.java

@Override
public void onResume() {
    super.onResume();
    if (materialDialog != null && !materialDialog.isShowing()) {
        materialDialog.show();//from   w ww  . j  a v  a2 s.c om
        materialDialog = null;
    }

    IntentFilter newFilter = new IntentFilter();
    newFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);
    newFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
    newFilter.addDataScheme(ContentResolver.SCHEME_FILE);
    registerReceiver(mainActivityHelper.mNotificationReceiver, newFilter);
    registerReceiver(receiver2, new IntentFilter(TAG_INTENT_FILTER_GENERAL));
    if (getSupportFragmentManager().findFragmentById(R.id.content_frame).getClass().getName()
            .contains("TabFragment")) {

        floatingActionButton.setVisibility(View.VISIBLE);
        floatingActionButton.showMenuButton(false);
    } else {

        floatingActionButton.setVisibility(View.INVISIBLE);
        floatingActionButton.hideMenuButton(false);
    }

    if (SDK_INT >= Build.VERSION_CODES.KITKAT) {
        // Registering intent filter for OTG
        IntentFilter otgFilter = new IntentFilter();
        otgFilter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
        otgFilter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
        registerReceiver(mOtgReceiver, otgFilter);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        // let's register encryption service to know when we've decrypted
        Intent encryptIntent = new Intent(this, EncryptService.class);
        bindService(encryptIntent, mEncryptServiceConnection, 0);

        if (!isEncryptOpen && encryptBaseFile != null) {
            // we've opened the file and are ready to delete it
            // don't move this to ondestroy as we'll be getting destroyed and starting
            // an async task just before it is not a good idea
            ArrayList<BaseFile> baseFiles = new ArrayList<>();
            baseFiles.add(encryptBaseFile);
            new DeleteTask(getContentResolver(), this).execute(baseFiles);
        }
    }
}

From source file:com.amaze.carbonfilemanager.activities.MainActivity.java

@Override
public void onNewIntent(Intent i) {
    intent = i;//  w  ww.j  a  v a 2 s. c  o  m
    path = i.getStringExtra("path");

    if (path != null) {
        if (new File(path).isDirectory()) {
            Fragment f = getDFragment();
            if ((f.getClass().getName().contains("TabFragment"))) {
                MainFragment m = ((MainFragment) getFragment().getTab());
                m.loadlist(path, false, OpenMode.FILE);
            } else
                goToMain(path);
        } else
            utils.openFile(new File(path), mainActivity);
    } else if (i.getStringArrayListExtra(TAG_INTENT_FILTER_FAILED_OPS) != null) {
        ArrayList<BaseFile> failedOps = i.getParcelableArrayListExtra(TAG_INTENT_FILTER_FAILED_OPS);
        if (failedOps != null) {
            mainActivityHelper.showFailedOperationDialog(failedOps, i.getBooleanExtra("move", false), this);
        }
    } else if (i.getCategories() != null && i.getCategories().contains(CLOUD_AUTHENTICATOR_GDRIVE)) {

        // we used an external authenticator instead of APIs. Probably for Google Drive
        CloudRail.setAuthenticationResponse(intent);

    } else if ((openProcesses = i.getBooleanExtra(KEY_INTENT_PROCESS_VIEWER, false))) {
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.content_frame, new ProcessViewer(), KEY_INTENT_PROCESS_VIEWER);
        //   transaction.addToBackStack(null);
        selectedStorage = SELECT_102;
        openProcesses = false;
        //title.setText(utils.getString(con, R.string.process_viewer));
        //Commit the transaction
        transaction.commitAllowingStateLoss();
        supportInvalidateOptionsMenu();
    } else if (intent.getAction() != null) {
        if (intent.getAction().equals(Intent.ACTION_GET_CONTENT)) {
            // file picker intent
            mReturnIntent = true;
            Toast.makeText(this, getString(R.string.pick_a_file), Toast.LENGTH_LONG).show();
        } else if (intent.getAction().equals(RingtoneManager.ACTION_RINGTONE_PICKER)) {
            // ringtone picker intent
            mReturnIntent = true;
            mRingtonePickerIntent = true;
            Toast.makeText(this, getString(R.string.pick_a_file), Toast.LENGTH_LONG).show();
        } else if (intent.getAction().equals(Intent.ACTION_VIEW)) {
            // zip viewer intent
            Uri uri = intent.getData();
            zippath = uri.toString();
            openZip(zippath);
        }

        if (SDK_INT >= Build.VERSION_CODES.KITKAT) {
            if (intent.getAction().equals(UsbManager.ACTION_USB_DEVICE_ATTACHED)) {
                if (sharedPref.getString(KEY_PREF_OTG, null) == null) {
                    sharedPref.edit().putString(KEY_PREF_OTG, VALUE_PREF_OTG_NULL).apply();
                    refreshDrawer();
                }
            } else if (intent.getAction().equals(UsbManager.ACTION_USB_DEVICE_DETACHED)) {
                sharedPref.edit().putString(KEY_PREF_OTG, null).apply();
                refreshDrawer();
            }
        }
    }
}