List of usage examples for android.bluetooth BluetoothDevice getAddress
public String getAddress()
From source file:uk.ac.horizon.ubihelper.service.channel.BluetoothDiscoveryChannel.java
protected synchronized void handlePollComplete() { if (pollInProgress) pollComplete();//from w ww . j a v a2 s . c o m try { JSONObject value = new JSONObject(); value.put(KEY_TIME, System.currentTimeMillis()); String btname = bluetooth.getName(); String btaddress = bluetooth.getAddress(); if (btname != null) value.put(KEY_NAME, btname); if (btaddress != null) value.put(KEY_ADDRESS, btaddress); JSONArray ds = new JSONArray(); value.put(KEY_DEVICES, ds); for (BluetoothDevice device : this.devices.values()) { JSONObject d = new JSONObject(); d.put(KEY_ADDRESS, device.getAddress()); BluetoothClass btclass = device.getBluetoothClass(); if (btclass != null) d.put(KEY_CLASS, btclass.getDeviceClass()); String name = device.getName(); if (name != null) d.put(KEY_NAME, name); d.put(KEY_BOND, device.getBondState()); ds.put(d); } onNewValue(value); } catch (JSONException e) { // shouldn't } }
From source file:com.hwx.wheel.steeringwheel.bluetooth.ScaleActivity.java
private boolean toCheck(BluetoothDevice device) { if (device.getAddress().equals(CONNECT_MAC)) { connect_device = device;//from w w w . ja va2 s .co m connDevice(connect_device.getAddress()); return true; } return false; }
From source file:com.megster.cordova.rfduino.RFduinoPlugin.java
@Override public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) { String address = device.getAddress(); if (!peripherals.containsKey(address)) { Peripheral peripheral = new Peripheral(device, rssi, scanRecord); peripherals.put(device.getAddress(), peripheral); if (discoverCallback != null) { PluginResult result = new PluginResult(PluginResult.Status.OK, peripheral.asJSONObject()); result.setKeepCallback(true); discoverCallback.sendPluginResult(result); }/*from w w w .jav a2 s .co m*/ } else { // this isn't necessary Peripheral peripheral = peripherals.get(address); peripheral.updateRssi(rssi); } }
From source file:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.activities.SensorSettingsActivity.java
private void openSelectDeviceDialog() { BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (mBluetoothAdapter != null) { BluetoothDevice[] mAllBondedDevices = (BluetoothDevice[]) mBluetoothAdapter.getBondedDevices() .toArray(new BluetoothDevice[0]); int mDeviceIndex = 0; if (mAllBondedDevices.length > 0) { int deviceCount = mAllBondedDevices.length; String[] deviceNames = new String[deviceCount]; for (int i = 0; i < deviceCount; i++) { BluetoothDevice device = mAllBondedDevices[i]; deviceNames[i] = device.getName() + "\n|" + device.getAddress(); if (deviceMacAdd.equals(device.getAddress())) { mDeviceIndex = i;//from w w w.j a va2 s . co m } } DialogFragment deviceDialog = new SelectDeviceDialogFragment(); Bundle args = new Bundle(); args.putStringArray("names", deviceNames); args.putInt("position", mDeviceIndex); args.putBoolean("device", true); deviceDialog.setArguments(args); getFragmentManager().beginTransaction(); deviceDialog.show(getSupportFragmentManager().beginTransaction(), "deviceDialog"); } } }
From source file:jp.co.kayo.ykmjuku.andylib.DeviceListActivity.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Bundle args = getArguments();/*www . j av a 2s. com*/ if (args != null) { mTag = args.getString("tag"); mSecure = args.getBoolean("secure"); } getDialog().setTitle(getString(R.string.select_device)); // Setup the window View root = inflater.inflate(R.layout.device_list, container, false); // Initialize the button to perform device discovery Button scanButton = (Button) root.findViewById(R.id.button_scan); scanButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { doDiscovery(); v.setVisibility(View.GONE); } }); // Initialize array adapters. One for already paired devices and // one for newly discovered devices mPairedDevicesArrayAdapter = new ArrayAdapter<String>(getActivity(), R.layout.device_name); mNewDevicesArrayAdapter = new ArrayAdapter<String>(getActivity(), R.layout.device_name); // Find and set up the ListView for paired devices ListView pairedListView = (ListView) root.findViewById(R.id.paired_devices); pairedListView.setAdapter(mPairedDevicesArrayAdapter); pairedListView.setOnItemClickListener(mDeviceClickListener); // Find and set up the ListView for newly discovered devices ListView newDevicesListView = (ListView) root.findViewById(R.id.new_devices); newDevicesListView.setAdapter(mNewDevicesArrayAdapter); newDevicesListView.setOnItemClickListener(mDeviceClickListener); // Register for broadcasts when a device is discovered IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND); getActivity().registerReceiver(mReceiver, filter); // Register for broadcasts when discovery has finished filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED); getActivity().registerReceiver(mReceiver, filter); // Get the local Bluetooth adapter mBtAdapter = BluetoothAdapter.getDefaultAdapter(); // Get a set of currently paired devices Set<BluetoothDevice> pairedDevices = mBtAdapter.getBondedDevices(); // If there are paired devices, add each one to the ArrayAdapter if (pairedDevices.size() > 0) { root.findViewById(R.id.title_paired_devices).setVisibility(View.VISIBLE); for (BluetoothDevice device : pairedDevices) { mPairedDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress()); } } else { String noDevices = getResources().getText(R.string.none_paired).toString(); mPairedDevicesArrayAdapter.add(noDevices); } return root; }
From source file:net.openracer.remote.DeviceListActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.i(LOGTAG, "on-create"); setContentView(R.layout.activity_device_list); getActionBar().setDisplayHomeAsUpEnabled(true); setResult(Activity.RESULT_CANCELED); Button scanButton = (Button) findViewById(R.id.button1); scanButton.setOnClickListener(new OnClickListener() { @Override/*from w w w. j a v a2 s.com*/ public void onClick(View v) { if (hasBtPerms()) { Log.e(LOGTAG, "pushed"); v.setEnabled(false); discoveredDevices.clear(); doDiscovery(); } } }); pairedDevices = new ArrayAdapter<String>(this, R.layout.btdevice_list_item); discoveredDevices = new ArrayAdapter<String>(this, R.layout.btdevice_list_item); ListView discoveredListView = (ListView) findViewById(R.id.listView2); discoveredListView.setAdapter(discoveredDevices); discoveredListView.setOnItemClickListener(deviceClickListener); ListView pairedListView = (ListView) findViewById(R.id.listView1); pairedListView.setAdapter(pairedDevices); pairedListView.setOnItemClickListener(deviceClickListener); registerReceiver(receiver, new IntentFilter(BluetoothDevice.ACTION_FOUND)); registerReceiver(receiver, new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED)); btAdapter = BluetoothAdapter.getDefaultAdapter(); if (btAdapter == null) { Log.e(LOGTAG, "No bluetooth adapter"); } if (!hasBtPerms()) { Button button = (Button) findViewById(R.id.button1); button.setText("No Bluetooth permissions"); button.setEnabled(false); } if (btAdapter != null) { if (!btAdapter.isEnabled()) { Button button = (Button) findViewById(R.id.button1); button.setText("Bluetooth not enabled"); button.setEnabled(false); } Set<BluetoothDevice> sysPairedDevices = btAdapter.getBondedDevices(); if (sysPairedDevices.isEmpty()) { pairedDevices.add("No paired devices."); } else { for (BluetoothDevice pDev : sysPairedDevices) { pairedDevices.add(pDev.getName() + "\n" + pDev.getAddress()); } } } else { Button button = (Button) findViewById(R.id.button1); button.setText("No Bluetooth device"); button.setEnabled(false); } }
From source file:edu.berkeley.cellscope.cscore.DeviceListActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Setup the window requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(R.layout.device_list); // Set result CANCELED in case the user backs out setResult(Activity.RESULT_CANCELED); // Initialize the button to perform device discovery Button scanButton = (Button) findViewById(R.id.button_scan); scanButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { doDiscovery();/* w ww . ja v a2 s . c o m*/ v.setVisibility(View.GONE); } }); // Initialize array adapters. One for already paired devices and // one for newly discovered devices mPairedDevicesArrayAdapter = new ArrayAdapter<String>(this, R.layout.device_name); mNewDevicesArrayAdapter = new ArrayAdapter<String>(this, R.layout.device_name); // Find and set up the ListView for paired devices ListView pairedListView = (ListView) findViewById(R.id.paired_devices); pairedListView.setAdapter(mPairedDevicesArrayAdapter); pairedListView.setOnItemClickListener(mDeviceClickListener); // Find and set up the ListView for newly discovered devices ListView newDevicesListView = (ListView) findViewById(R.id.new_devices); newDevicesListView.setAdapter(mNewDevicesArrayAdapter); newDevicesListView.setOnItemClickListener(mDeviceClickListener); // Register for broadcasts when a device is discovered IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND); this.registerReceiver(mReceiver, filter); // Register for broadcasts when discovery has finished filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED); this.registerReceiver(mReceiver, filter); // Get the local Bluetooth adapter mBtAdapter = BluetoothAdapter.getDefaultAdapter(); // Get a set of currently paired devices Set<BluetoothDevice> pairedDevices = mBtAdapter.getBondedDevices(); // If there are paired devices, add each one to the ArrayAdapter if (pairedDevices.size() > 0) { findViewById(R.id.title_paired_devices).setVisibility(View.VISIBLE); for (BluetoothDevice device : pairedDevices) { mPairedDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress()); } } else { String noDevices = getResources().getText(R.string.none_paired).toString(); mPairedDevicesArrayAdapter.add(noDevices); } }
From source file:com.example.android.bluetoothchat.DeviceListActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // ??// w w w . ja v a 2 s . c o m requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(R.layout.activity_device_list); // ????????????CANCELED setResult(Activity.RESULT_CANCELED); // ???????? Button scanButton = (Button) findViewById(R.id.button_scan); scanButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { doDiscovery(); v.setVisibility(View.GONE); } }); //??????? Button startchatButton = (Button) findViewById(R.id.button_start_chat); startchatButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { connect(); } }); // array adapters??. // ?????????????? ArrayAdapter<String> pairedDevicesArrayAdapter = new ArrayAdapter<String>(this, R.layout.device_name); mNewDevicesArrayAdapter = new ArrayAdapter<String>(this, R.layout.device_name); // ????ListView? pairedListView = (ListView) findViewById(R.id.paired_devices); pairedListView.setAdapter(pairedDevicesArrayAdapter); pairedListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); // ????????ListView? ListView newDevicesListView = (ListView) findViewById(R.id.new_devices); newDevicesListView.setAdapter(mNewDevicesArrayAdapter); newDevicesListView.setOnItemClickListener(mDeviceClickListener); // ???? IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND); this.registerReceiver(mReceiver, filter); // ??? filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED); this.registerReceiver(mReceiver, filter); // local Bluetooth adapter?? mBtAdapter = BluetoothAdapter.getDefaultAdapter(); // ???? Set<BluetoothDevice> pairedDevices = mBtAdapter.getBondedDevices(); // ????????ArrayAdapter?? if (pairedDevices.size() > 0) { findViewById(R.id.title_paired_devices).setVisibility(View.VISIBLE); for (BluetoothDevice device : pairedDevices) { pairedDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress()); } } else { String noDevices = getResources().getText(R.string.none_paired).toString(); pairedDevicesArrayAdapter.add(noDevices); } }
From source file:no.nordicsemi.android.nrftoolbox.dfu.DfuInitiatorActivity.java
@Override public void onDeviceSelected(final BluetoothDevice device, final String name) { final Intent intent = getIntent(); final String overwritenName = intent.getStringExtra(DfuService.EXTRA_DEVICE_NAME); final String path = intent.getStringExtra(DfuService.EXTRA_FILE_PATH); final String address = device.getAddress(); final String finalName = overwritenName == null ? name : overwritenName; // Start DFU service with data provided in the intent final Intent service = new Intent(this, DfuService.class); service.putExtra(DfuService.EXTRA_DEVICE_ADDRESS, address); service.putExtra(DfuService.EXTRA_DEVICE_NAME, finalName); service.putExtra(DfuService.EXTRA_FILE_PATH, path); startService(service);/*w w w . ja v a 2s. c om*/ finish(); }
From source file:org.envirocar.app.application.service.DeviceInRangeService.java
protected void verifyRemoteDevice(Intent intent) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); String targetDeviceFromSettings = preferences.getString(SettingsActivity.BLUETOOTH_KEY, null); if (targetDeviceFromSettings != null) { BluetoothDevice discoveredDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); logger.info("Found Device: " + discoveredDevice.getName() + " / " + discoveredDevice.getAddress()); if (targetDeviceFromSettings.equals(discoveredDevice.getAddress())) { initializeConnection(discoveredDevice); }/*from w w w . j a va 2s . c o m*/ } }