List of usage examples for android.bluetooth BluetoothDevice EXTRA_DEVICE
String EXTRA_DEVICE
To view the source code for android.bluetooth BluetoothDevice EXTRA_DEVICE.
Click Source Link
From source file:com.nordicsemi.ImageTransferDemo.MainActivity.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case REQUEST_SELECT_DEVICE: //When the DeviceListActivity return, with the selected device address if (resultCode == Activity.RESULT_OK && data != null) { String deviceAddress = data.getStringExtra(BluetoothDevice.EXTRA_DEVICE); mDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(deviceAddress); Log.d(TAG, "... onActivityResultdevice.address==" + mDevice + "mserviceValue" + mService); //((TextView) findViewById(R.id.deviceName)).setText(mDevice.getName()+ " - connecting"); mService.connect(deviceAddress); mConnectionProgDialog.show(); }// ww w . java 2 s . co m break; case REQUEST_ENABLE_BT: // When the request to enable Bluetooth returns if (resultCode == Activity.RESULT_OK) { Toast.makeText(this, "Bluetooth has turned on ", Toast.LENGTH_SHORT).show(); } else { // User did not enable Bluetooth or an error occurred Log.d(TAG, "BT not enabled"); Toast.makeText(this, "Problem in BT Turning ON ", Toast.LENGTH_SHORT).show(); finish(); } break; default: Log.e(TAG, "wrong request code"); break; } }
From source file:com.zpci.firstsignhairclipdemo.MainActivity.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case REQUEST_SELECT_DEVICE: //When the DeviceListActivity return, with the selected device address if (resultCode == Activity.RESULT_OK && data != null) { String deviceAddress = data.getStringExtra(BluetoothDevice.EXTRA_DEVICE); mDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(deviceAddress); Log.d(TAG, "... onActivityResultdevice.address==" + mDevice + "mserviceValue" + mService); ((TextView) findViewById(R.id.deviceName)).setText(mDevice.getName() + " - connecting"); mService.connect(deviceAddress); }/*w w w. ja v a 2 s . c o m*/ break; case REQUEST_ENABLE_BT: // When the request to enable Bluetooth returns if (resultCode == Activity.RESULT_OK) { Toast.makeText(this, "Bluetooth has turned on ", Toast.LENGTH_SHORT).show(); } else { // User did not enable Bluetooth or an error occurred Log.d(TAG, "BT not enabled"); Toast.makeText(this, "Problem in BT Turning ON ", Toast.LENGTH_SHORT).show(); finish(); } break; case REQUEST_DIAG_CMD: if (resultCode == Activity.RESULT_OK) { byte[] value = data.getByteArrayExtra("cmd"); Log.d(TAG, "Diag command request success. length = " + value.length + ", 0x" + Integer.toHexString(value[0] & 0xff) + ", " + value[0]); if (value[0] == (byte) 0x05) { //alarm arm/disarm if (value[1] == (byte) 0x00) { armed = true; alarmsent = false; adStream.reset(); // reset audio data buffer expectedAudioSamples = ALARMAUDIOSAMPLES; // set to default number of samples SensorStream.reset(); // reset sensor data buffer expectedSensorSamples = ALARMSENSORSAMPLES; // set to default } else armed = false; } try { mService.writeRXCharacteristic(value); } catch (Exception e) { Log.e(TAG, e.toString()); } ; //Update the log with time stamp and message sent String msg = ""; for (int i = 0; i < value.length; i++) { msg = msg + "0x" + Integer.toHexString(value[i] & 0xff) + " "; } String currentDateTimeString = DateFormat.getTimeInstance().format(new Date()); listAdapter.add("[" + currentDateTimeString + "] TX: " + msg); messageListView.smoothScrollToPosition(listAdapter.getCount() - 1); } else { Log.d(TAG, "Diag command request result fail"); } break; default: Log.e(TAG, "bad activity result request code"); break; } }
From source file:edu.stanford.mobisocial.dungbeetle.NearbyActivity.java
private void findBluetooth() { if (!BluetoothAdapter.getDefaultAdapter().isEnabled()) { Intent bt = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(bt, RESULT_BT_ENABLE); return;//w w w .j a v a2 s .com } // Create a BroadcastReceiver for ACTION_FOUND final IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND); filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED); final BroadcastReceiver receiver = new BroadcastReceiver() { public void onReceive(final Context context, final Intent intent) { String action = intent.getAction(); // When discovery finds a device if (BluetoothDevice.ACTION_FOUND.equals(action)) { new Thread() { public void run() { BluetoothBeacon.OnDiscovered discovered = new BluetoothBeacon.OnDiscovered() { @Override public void onDiscovered(final byte[] data) { runOnUiThread(new Runnable() { @Override public void run() { try { JSONObject obj = new JSONObject(new String(data)); mNearbyList.add( new NearbyItem(NearbyItem.Type.FEED, obj.getString("name"), Uri.parse(obj.getString("dynuri")), null)); mAdapter.notifyDataSetChanged(); } catch (JSONException e) { Log.e(TAG, "Error getting group info over bluetooth", e); } } }); } }; // Get the BluetoothDevice object from the Intent BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); BluetoothBeacon.discover(NearbyActivity.this, device, discovered); }; }.start(); } if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) { unregisterReceiver(this); } } }; registerReceiver(receiver, filter); // Don't forget to unregister during // onDestroy BluetoothAdapter.getDefaultAdapter().startDiscovery(); Toast.makeText(this, "Scanning Bluetooth...", 500).show(); }