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:com.swiftnav.piksidroid.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    this.setupUI();

    UsbManager mUsbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
    PendingIntent mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
    IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
    registerReceiver(mUsbReceiver, filter);

    filter = new IntentFilter(UsbManager.ACTION_USB_DEVICE_DETACHED);
    registerReceiver(mUsbReceiverDisconnect, filter);

    HashMap<String, UsbDevice> deviceList = mUsbManager.getDeviceList();

    for (UsbDevice device : deviceList.values()) {
        if ((device.getVendorId() == Utils.PIKSI_VID) && (device.getProductId() == Utils.PIKSI_PID))
            if (!mUsbManager.hasPermission(device)) {
                mUsbManager.requestPermission(device, mPermissionIntent);
            } else {
                ((EditText) findViewById(R.id.console)).setText("");
                piksiConnected(device);// w w  w  . j a v  a 2s .c  o m
            }
    }
}

From source file:org.deviceconnect.android.deviceplugin.fabo.setting.fragment.FaBoConnectFragment.java

@Override
public void onResume() {
    super.onResume();

    // USB????Broadcast Receiver.
    IntentFilter mIntentFilter = new IntentFilter();
    mIntentFilter.addAction(FaBoConst.DEVICE_TO_ARDUINO_OPEN_USB_RESULT);
    mIntentFilter.addAction(FaBoConst.DEVICE_TO_ARDUINO_CHECK_USB_RESULT);
    mIntentFilter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
    mContext.registerReceiver(mUSBResultEvent, mIntentFilter);

    // Arduino Uno???.
    Intent intent = new Intent(FaBoConst.DEVICE_TO_ARDUINO_CHECK_USB);
    mContext.sendBroadcast(intent);/*from   w w  w .  j  av  a 2s . co m*/

    // USB???.
    UsbManager manager = (UsbManager) mContext.getSystemService(Context.USB_SERVICE);
    HashMap<String, UsbDevice> deviceList = manager.getDeviceList();

    for (UsbDevice device : deviceList.values()) {
        if (device.getVendorId() == 10755) {
            mActivity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    mTextViewCommment.setText(R.string.arduinoorg_find);
                    mOutputButton.setEnabled(false);
                }
            });
        } else if (device.getVendorId() == 9025) {
            mActivity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    mTextViewCommment.setText(R.string.arduinocc_find);
                    mOutputButton.setEnabled(true);
                }
            });
            break;
        }
    }
}

From source file:com.grupohqh.carservices.operator.ReadTagActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_read_tag);

    URL = getString(R.string.base_url) + getString(R.string.findcarid_url);
    if (getIntent().getExtras().containsKey("userId"))
        userId = getIntent().getExtras().getInt("userId");

    rgSearchBy = (RadioGroup) findViewById(R.id.rgSearchBy);
    etTag = (EditText) findViewById(R.id.etTag);
    etLicensePlate = (EditText) findViewById(R.id.etLicensePlate);
    etSerialNumber = (EditText) findViewById(R.id.etSerialNumber);
    btnSearch = (Button) findViewById(R.id.btnSearch);
    viewTag = findViewById(R.id.viewTag);
    viewPlate = findViewById(R.id.viewPlate);
    viewSerial = findViewById(R.id.viewSerial);

    changeVisibility(rgSearchBy.getCheckedRadioButtonId());

    rgSearchBy.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        @Override/*w  ww  .  ja  va2 s.com*/
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            changeVisibility(checkedId);
        }
    });

    btnSearch.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (validate()) {
                new HttpAsyncTask().execute(URL);
            }
        }
    });

    if (useMiniMe) {
        manager = (UsbManager) getSystemService(Context.USB_SERVICE);
        usbCommunication = UsbCommunication.newInstance();

        IntentFilter filter = new IntentFilter();
        filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED); // will intercept by system
        filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
        filter.addAction(ACTION_USB_PERMISSION);
        registerReceiver(usbReceiver, filter);
        etEpc = (EditText) findViewById(R.id.etEPC);
        btnRead = (Button) findViewById(R.id.btnReadTAG);
        txtStatus = (TextView) findViewById(R.id.txtStatus);

        btnRead.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                etEpc.setText("");
                if (txtStatus.getText().toString().equals("conectado")) {
                    readTag();
                } else {
                    Toast.makeText(getBaseContext(), "dispositivo " + txtStatus.getText(), Toast.LENGTH_LONG)
                            .show();
                }
            }
        });
    }
}

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

@Override
public void onCreate(Bundle savedInstanceState) {

    String action = this.getIntent().getAction();
    if (action == null)
        action = "";

    if (!action.equals(UsbManager.ACTION_USB_DEVICE_ATTACHED)
            && !action.equals(UsbManager.ACTION_USB_ACCESSORY_ATTACHED)) {

        this.setTheme(android.R.style.Theme_Holo);
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        IntentFilter usbFilter = new IntentFilter();
        usbFilter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
        usbFilter.addAction(UsbManager.ACTION_USB_ACCESSORY_DETACHED);

        registerReceiver(mUsbReceiver, usbFilter);

        LocalBroadcastManager bManager = LocalBroadcastManager.getInstance(this);
        IntentFilter playFilter = new IntentFilter();
        playFilter.addAction(BANNER);/*from  w w w  .  ja v  a  2  s  . c  o  m*/
        playFilter.addAction(CLOSE);
        bManager.registerReceiver(mPlayReceiver, playFilter);

        mSongText = (TextView) findViewById(R.id.tvPodSongName);
        mProcessText = (TextView) findViewById(R.id.tvPodProcess);
        mAppIcon = (ImageView) findViewById(R.id.ivAppIcon);

        Intent serviceIntent = new Intent(this, PodModeService.class);
        startService(serviceIntent);

    } else {

        super.onCreate(savedInstanceState);

        mStartViaUSB = true;

        Intent serviceIntent = new Intent("me.spadival.podmode.PodModeService");

        startService(serviceIntent);
        finish(); // If started via USB insert, this activity is done
                  // here -
                  // don't want the view coming in the way..
    }

}

From source file:com.android.usbtuner.UsbInputController.java

@Override
public void onReceive(Context context, Intent intent) {
    if (DEBUG)/*from  w  w w .  j  av  a 2 s.  co m*/
        Log.d(TAG, "Broadcast intent received:" + intent);

    if (!Features.USB_TUNER.isEnabled(context)) {
        enableUsbTunerTvInputService(context, false);
        return;
    }

    switch (intent.getAction()) {
    case Intent.ACTION_BOOT_COMPLETED:
    case UsbManager.ACTION_USB_DEVICE_ATTACHED:
    case UsbManager.ACTION_USB_DEVICE_DETACHED:
        // Tuner is supported on MNC and later version only.
        boolean enabled = IS_MNC_OR_LATER && isTunerConnected(context);
        mHandler.removeMessages(MSG_ENABLE_INPUT_SERVICE);
        if (enabled) {
            // Need to check if DVB driver is accessible. Since the driver creation
            // could be happen after the USB event, delay the checking by
            // DVB_DRIVER_CHECK_DELAY_MS.
            mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_ENABLE_INPUT_SERVICE, context),
                    DVB_DRIVER_CHECK_DELAY_MS);
        } else {
            enableUsbTunerTvInputService(context, false);
        }
        break;
    }
}

From source file:org.ros.android.android_acm_serial.AcmDeviceActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    usbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
    usbPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
    registerReceiver(usbDevicePermissionReceiver, new IntentFilter(ACTION_USB_PERMISSION));
    registerReceiver(usbDeviceDetachedReceiver, new IntentFilter(UsbManager.ACTION_USB_DEVICE_DETACHED));
    onUsbDeviceAttached(getIntent());//from w ww. j ava 2 s  .c  o  m
}

From source file:org.deviceconnect.android.deviceplugin.fabo.setting.fragment.FaBoFirmwareFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // Root view.
    View root = inflater.inflate(R.layout.firmata, container, false);

    // Get context.
    mContext = getActivity().getBaseContext();
    mActivity = getActivity();/*from w ww .j a  va2s . c  o  m*/

    // Get ui component.
    mTextViewCommment = (TextView) root.findViewById(R.id.textViewComment);
    mButtonConnect = (Button) root.findViewById(R.id.buttonConnect);
    mButtonSend = (Button) root.findViewById(R.id.buttonSend);
    mButtonBack = (Button) root.findViewById(R.id.buttonBack);

    // USB??
    mButtonConnect.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            // FaBo???USBClose?.
            Intent intent = new Intent(FaBoConst.DEVICE_TO_ARDUINO_CLOSE_USB);
            mContext.sendBroadcast(intent);

            // ????USB??.
            if (mStkWriter.openUsb()) {
                mButtonSend.setVisibility(Button.VISIBLE);
                mButtonSend.setEnabled(true);
            }
        }
    });

    // .
    mButtonBack.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            // FaBo???USBClose?.
            Intent intent = new Intent(FaBoConst.DEVICE_TO_ARDUINO_CHECK_USB);
            mContext.sendBroadcast(intent);

            // ???.
            mParent.moveConnectFirmata();
        }
    });

    // Firmware??
    mButtonSend.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mButtonSend.setEnabled(false);

            // Firmware?.
            mStkWriter.setData(R.raw.standardfirmata_hex);
            mStkWriter.sendFirmware();
        }
    });

    // USB????Receiver??.
    IntentFilter filter = new IntentFilter();
    filter.addAction(StkWriter.ACTION_USB_PERMISSION);
    filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
    getActivity().registerReceiver(mUsbReceiver, filter);

    return root;
}

From source file:com.cyanogenmod.settings.otgtoggle.UsbDeviceMonitorService.java

@Override
public void onCreate() {
    super.onCreate();

    mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    mUsbManager = (UsbManager) getSystemService(USB_SERVICE);

    mStateMachine = new UsbPortStateMachine(this);
    mStateMachine.setDbg(true); // XXX
    mStateMachine.start();/*from   w ww . jav a  2s .c om*/

    IntentFilter filter = new IntentFilter();
    filter.addAction(AudioManager.ACTION_HEADSET_PLUG);
    filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
    filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
    registerReceiver(mDeviceStateReceiver, filter);
}

From source file:com.ksksue.app.ftdi_uart.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //initialize GoogleApiClient instance for location
    mGoogleApiClient = new GoogleApiClient.Builder(this).addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this).addApi(LocationServices.API).addApi(AppIndex.API).build();

    tvRead = (TextView) findViewById(R.id.tvRead);
    tvRead.setMovementMethod(new ScrollingMovementMethod());

    logRead = (TextView) findViewById(R.id.logRead);
    logRead.setMovementMethod(new ScrollingMovementMethod());

    etWrite = (EditText) findViewById(R.id.etWrite);

    btWrite = (Button) findViewById(R.id.btWrite);
    debuger = (Button) findViewById(R.id.debug);
    joinBtn = (Button) findViewById(R.id.joinBtn);

    List<String> list = new ArrayList<String>();
    list.add("Everyone");
    spinnerDataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list);
    makeSpinner(spinnerDataAdapter);//from   w ww.ja v a 2s  .  c  om

    updateView(false);

    try {
        ftD2xx = D2xxManager.getInstance(this);
    } catch (D2xxManager.D2xxException ex) {
        Log.e(TAG, ex.toString());
    }

    IntentFilter filter = new IntentFilter();
    filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
    filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
    registerReceiver(mUsbReceiver, filter);

}

From source file:com.jjoe64.graphview_demos.fragments.Home.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.fragment_home, container, false);

    if (SHOW_DEBUG) {
        Log.d(TAG, "New FTDriver");
    }//w w  w .  j a  v a 2s. c o m

    // get service
    mSerial = new Physicaloid(getActivity());

    if (SHOW_DEBUG) {
        Log.d(TAG, "New instance : " + mSerial);
    }
    // listen for new devices
    IntentFilter filter = new IntentFilter();
    filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
    filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
    getActivity().registerReceiver(mUsbReceiver, filter);

    if (SHOW_DEBUG) {
        Log.d(TAG, "FTDriver beginning");
    }
    closeUsbSerial();
    openUsbSerial();

    return rootView;
}