List of usage examples for android.hardware.usb UsbManager ACTION_USB_DEVICE_ATTACHED
String ACTION_USB_DEVICE_ATTACHED
To view the source code for android.hardware.usb UsbManager ACTION_USB_DEVICE_ATTACHED.
Click Source Link
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);/* w w w. j a v a 2s. com*/ 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.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//from w ww . j a v a 2 s .c om 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:com.googlecode.android_scripting.facade.USBHostSerialFacade.java
/** * registerIntent: from usbserialConnect {{{1 *//*from www. j av a 2 s . c om*/ private void registerIntent() { if (mReceiver != null) { // this function was already called. return; } Log.d("Register USB Intents..."); IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION); filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED); mReceiver = new USBHostSerialReceiver(); mService.registerReceiver(mReceiver, filter); }
From source file:com.android.usbtuner.UsbInputController.java
@Override public void onReceive(Context context, Intent intent) { if (DEBUG)// w w w . ja v a 2s. c o 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.chromium.latency.walt.MainActivity.java
@Override protected void onResume() { super.onResume(); final UsbDevice usbDevice; Intent intent = getIntent();/*from ww w . j a v a 2 s. c om*/ if (intent != null && intent.getAction().equals(UsbManager.ACTION_USB_DEVICE_ATTACHED)) { setIntent(null); // done with the intent usbDevice = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE); } else { usbDevice = null; } // Connect and sync clocks, but a bit later as it takes time handler.postDelayed(new Runnable() { @Override public void run() { if (usbDevice == null) { waltDevice.connect(); } else { waltDevice.connect(usbDevice); } } }, 1000); if (intent != null && AutoRunFragment.TEST_ACTION.equals(intent.getAction())) { getSupportFragmentManager().popBackStack("Automated Test", FragmentManager.POP_BACK_STACK_INCLUSIVE); Fragment autoRunFragment = new AutoRunFragment(); autoRunFragment.setArguments(intent.getExtras()); switchScreen(autoRunFragment, "Automated Test"); } }
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();// ww w .jav a 2s . c o m 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);// w w w . j a v a 2s. co m 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:org.ros.android.android_acm_serial.AcmDeviceActivity.java
private void onUsbDeviceAttached(Intent intent) { if (intent.getAction().equals(UsbManager.ACTION_USB_DEVICE_ATTACHED)) { UsbDevice usbDevice = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE); String deviceName = usbDevice.getDeviceName(); if (!acmDevices.containsKey(deviceName)) { newAcmDevice(usbDevice);/*from w ww . j a v a 2s. c om*/ } else if (DEBUG) { log.info("Ignoring already connected device: " + deviceName); } } }
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"); }/*from w ww. j a va2 s . 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; }
From source file:svenmeier.coxswain.MainActivity.java
/** * Check whether the intent contains a {@link UsbDevice}, and pass it to {@link GymService}. * * @param intent possible USB device connect *//*from w w w . j av a2 s . c om*/ private boolean checkUsbDevice(Intent intent) { if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(intent.getAction())) { UsbDevice device = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE); if (device != null) { GymService.start(this, device); if (gym.program == null) { // try to unlock device - has no effect if this activity is already running :/ getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); } else { // program is already selected so restart workout WorkoutActivity.start(this); } } return true; } return false; }