List of usage examples for android.hardware.usb UsbManager ACTION_USB_ACCESSORY_DETACHED
String ACTION_USB_ACCESSORY_DETACHED
To view the source code for android.hardware.usb UsbManager ACTION_USB_ACCESSORY_DETACHED.
Click Source Link
From source file:com.egoclean.arm.ui.ArmActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mUsbManager = (UsbManager) getSystemService(Context.USB_SERVICE); mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0); IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION); filter.addAction(UsbManager.ACTION_USB_ACCESSORY_DETACHED); registerReceiver(mUsbReceiver, filter); outputController = new OutputController(this); setContentView(R.layout.main);// w w w.j a va2 s .com ArmView armView = (ArmView) findViewById(R.id.arm_view); armView.setAngleListener(outputController); mNotConnected = findViewById(R.id.lnl_not_connected); if (mAccessory != null) { showControls(); } else { hideControls(); } }
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 ava2s.co 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.nfc.gemkey.MainActivity.java
@Override public void onCreate(Bundle icicle) { if (DEBUG)//from w w w. j ava 2s . com Log.d(TAG, "onCreate"); super.onCreate(icicle); setContentView(R.layout.activity_main); mAdapter = NfcAdapter.getDefaultAdapter(this); // Create a generic PendingIntent that will be deliver to this activity. The NFC stack // will fill in the intent with the details of the discovered tag before delivering to // this activity. mPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); // Setup an intent filter for all MIME based dispatches IntentFilter tagDetected = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED); tagDetected.addCategory(Intent.CATEGORY_DEFAULT); mFilters = new IntentFilter[] { tagDetected }; mUsbManager = (UsbManager) getSystemService(Context.USB_SERVICE); mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0); IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION); filter.addAction(UsbManager.ACTION_USB_ACCESSORY_DETACHED); registerReceiver(mUsbReceiver, filter); if (getLastNonConfigurationInstance() != null) { Log.i(TAG, "open usb accessory@onCreate"); mAccessory = (UsbAccessory) getLastNonConfigurationInstance(); openAccessory(mAccessory); } buttonLED = (ToggleButton) findViewById(R.id.nfc_btn); buttonLED.setBackgroundResource( buttonLED.isChecked() ? R.drawable.btn_toggle_yes : R.drawable.btn_toggle_no); buttonLED.setOnCheckedChangeListener(mKeyLockListener); tagId = (TextView) findViewById(R.id.nfc_tag); tagId.setText(R.string.nfc_scan_tag); // Avoid NetworkOnMainThreadException StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites() .detectNetwork().penaltyLog().build()); StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects() .detectLeakedClosableObjects().penaltyLog().penaltyDeath().build()); setVolumeControlStream(AudioManager.STREAM_MUSIC); }
From source file:nl.bennyjacobs.aapbridge.aap.UsbConnection.java
public UsbConnection(Context context, UsbManager usbManager, UsbAccessory accessory) throws IOException { mContext = context;//w ww . j ava 2 s . c o m mAccessory = accessory; mFileDescriptor = usbManager.openAccessory(accessory); if (mFileDescriptor == null) { throw new IOException("Could not open accessory"); } FileDescriptor fd = mFileDescriptor.getFileDescriptor(); mInputStream = new BufferedInputStream(new FileInputStream(fd)); mOutputStream = new BufferedOutputStream(new FileOutputStream(fd)); IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION); filter.addAction(UsbManager.ACTION_USB_ACCESSORY_DETACHED); //mContext.registerReceiver(mUsbReceiver, filter); }
From source file:tv.piratemedia.flightcontroller.BluetoothComputerFragment.java
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { mTransactionView = (ListView) view.findViewById(R.id.list); throttle = (VerticalProgressBar) view.findViewById(R.id.throttle); LedColor = (ImageView) view.findViewById(R.id.LedColor); rollLeft = (ProgressBar) view.findViewById(R.id.rollLeft); rollRight = (ProgressBar) view.findViewById(R.id.rollRight); pitchForward = (VerticalProgressBar) view.findViewById(R.id.pitchForward); pitchBackward = (VerticalProgressBar) view.findViewById(R.id.pitchBackward); yawLeft = (ProgressBar) view.findViewById(R.id.yawLeft); yawRight = (ProgressBar) view.findViewById(R.id.yawRight); mUsbManager = (UsbManager) getActivity().getSystemService(Context.USB_SERVICE); mPermissionIntent = PendingIntent.getBroadcast(getActivity(), 0, new Intent(ACTION_USB_PERMISSION), 0); IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION); filter.addAction(UsbManager.ACTION_USB_ACCESSORY_DETACHED); getActivity().registerReceiver(mUsbReceiver, filter); if (getActivity().getLastNonConfigurationInstance() != null) { mAccessory = (UsbAccessory) getActivity().getLastNonConfigurationInstance(); openAccessory(mAccessory);//from ww w. j a va2s . c om } setupAtimiter(); setupGPS(); //setupGyro(); setupAccel(); }
From source file:com.rp.podemu.MainActivity.java
@Override public void onResume() { super.onResume(); try {/*from w w w . ja v a 2 s. co m*/ loadPreferences(); start_service(null); iF = new PodEmuIntentFilter(); iF.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED); iF.addAction(UsbManager.ACTION_USB_ACCESSORY_DETACHED); // iF.addDataScheme("content"); // iF.addDataAuthority(ctrlAppProcessName, null); registerReceiver(mReceiver, iF); PodEmuLog.debug("onResume done"); } catch (Exception e) { PodEmuLog.printStackTrace(e); throw e; } }
From source file:com.rp.podemu.PodEmuService.java
@Override public void onCreate() { super.onCreate(); try {//from ww w .j av a 2 s. c o m serialInterfaceBuilder = new SerialInterfaceBuilder(); //SharedPreferences sharedPref = this.getSharedPreferences("PODEMU_PREFS", Context.MODE_PRIVATE); //String ctrlAppProcessName = sharedPref.getString("ControlledAppProcessName", "unknown app"); iF = new PodEmuIntentFilter(); iF.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED); iF.addAction(UsbManager.ACTION_USB_ACCESSORY_DETACHED); registerReceiver(mReceiver, iF); reloadBaudRate(); } catch (Exception e) { PodEmuLog.printStackTrace(e); throw e; } }
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;// ww w . j av a2 s . 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); }