List of usage examples for android.bluetooth BluetoothDevice getAddress
public String getAddress()
From source file:io.github.msc42.masterthemaze.SearchDeviceActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); lockScreenOrientation();//from w w w.ja v a 2s.c om setContentView(R.layout.activity_search_device); mSearchNoteTextView = (TextView) findViewById(R.id.searchNoteTextView); mBluetoothDevicesListView = (ListView) findViewById(R.id.bluetoothDevicesListView); mBluetoothDevicesListView .setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mDevicesList)); mBluetoothDevicesListView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { if (mBluetoothAdapter != null) { mBluetoothAdapter.cancelDiscovery(); } BluetoothDevice device = mDevices.get(position); startMainActivity(device.getName(), device.getAddress()); } }); if (startBluetooth()) { searchDevices(); } }
From source file:com.mattprecious.notisync.preferences.DevicePreferenceFragment.java
@Override public void onResume() { super.onResume(); BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter(); if (btAdapter == null) { return;/* ww w .ja v a 2 s .co m*/ } PreferenceScreen screen = getPreferenceScreen(); screen.removeAll(); Set<String> selectedDevices = Preferences.getDevices(getActivity()); // Get a set of currently paired devices Set<BluetoothDevice> pairedDevices = btAdapter.getBondedDevices(); for (BluetoothDevice device : pairedDevices) { CheckBoxPreference preference = new CheckBoxPreference(getActivity()); preference.setOnPreferenceChangeListener(preferenceListener); preference.setTitle(device.getName()); preference.setSummary(device.getAddress()); int iconResId = Helpers.getBtClassDrawable(device); if (iconResId != 0) { preference.setIcon(iconResId); } if (selectedDevices.contains(device.getAddress())) { preference.setDefaultValue(true); localDeviceSet.add(device.getAddress()); } getPreferenceScreen().addPreference(preference); } }
From source file:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.MyHealthHubGlassMainActivity.java
private void openSelectDeviceDialog(String sensorType) { 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]; int i = 0; for (BluetoothDevice device : mAllBondedDevices) { deviceNames[i++] = device.getName() + "|" + device.getAddress(); }/* w ww .ja v a 2s . com*/ DialogFragment deviceDialog = new SelectDeviceDialogFragment(); Bundle args = new Bundle(); args.putString("sensorType", sensorType); 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:com.ahmedabdelmeged.bluetoothmc.ui.BluetoothDevices.java
/** * get the paired devices in the phone/* w w w . j a va 2s . c o m*/ */ private void PairedDevicesList() { pairedDevices = mBluetoothAdapter.getBondedDevices(); if (pairedDevices.size() > 0) { for (BluetoothDevice bt : pairedDevices) { //Get the device's name and the address bluetoothDevicesAdapter.addDevice(bt.getName() + "\n" + bt.getAddress()); } } else { Toast.makeText(getApplicationContext(), R.string.no_paired_devices, Toast.LENGTH_LONG).show(); } }
From source file:com.megster.cordova.ble.central.BLECentralPlugin.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 www . j a va2 s. c o m } else { // this isn't necessary Peripheral peripheral = peripherals.get(address); peripheral.updateRssi(rssi); } // TODO offer option to return duplicates }
From source file:io.github.msc42.masterthemaze.SearchDeviceActivity.java
private void showBoundedDevices() { Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices(); for (BluetoothDevice device : pairedDevices) { if (!mDevices.contains(device)) { mDevices.add(device);/*from w ww. ja va 2s . c o m*/ mDevicesList.add(device.getName() + "\n" + device.getAddress()); mBluetoothDevicesListView.setAdapter( new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mDevicesList)); } } }
From source file:com.example.mego.adas.bluetooth.ConnectFragment.java
/** * get the paired devices in the phone// w w w.j a v a2 s .co m */ private void PairedDevicesList() { pairedDevices = mBluetoothAdapter.getBondedDevices(); if (pairedDevices.size() > 0) { for (BluetoothDevice bt : pairedDevices) { emptyTextView.setVisibility(View.INVISIBLE); //Get the device's name and the address bluetoothDevicesAdapter.setDevice(bt.getName() + "\n" + bt.getAddress()); } } else { makeText(getContext(), R.string.no_paired_devices, Toast.LENGTH_LONG).show(); emptyTextView.setVisibility(View.VISIBLE); } }
From source file:org.chromium.ChromeBluetooth.java
private JSONObject getBasicDeviceInfo(BluetoothDevice device) throws JSONException { JSONObject deviceInfo = new JSONObject(); deviceInfo.put("address", device.getAddress()); deviceInfo.put("name", device.getName()); deviceInfo.put("deviceClass", device.getBluetoothClass().getDeviceClass()); deviceInfo.put("paired", device.getBondState() == BluetoothDevice.BOND_BONDED); deviceInfo.put("connected", isConnected(device)); deviceInfo.put("uuids", new JSONArray(getUuidStringsFromDevice(device))); return deviceInfo; }
From source file:com.javadog.bluetoothproximitylock.BluetoothFragment.java
protected void populateBtDevices() { //Get a Set of all paired bluetooth devices, convert to array BluetoothManager.refreshBtDevices(); devicesSet = BluetoothManager.getAllBtDevices(); ArrayList<String> devices = new ArrayList<>(); for (BluetoothDevice b : devicesSet) { devices.add(b.getName() + " (" + b.getAddress() + ")"); }/*from w w w . j a va 2 s .c o m*/ //Set the adapter for the device spinner deviceChooser.setAdapter(new ArrayAdapter<>(getActivity().getApplicationContext(), android.R.layout.simple_spinner_dropdown_item, devices)); }
From source file:org.jfedor.nxtremotecontrol.ChooseDeviceActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(R.layout.device_list); setResult(Activity.RESULT_CANCELED); Button scanButton = (Button) findViewById(R.id.button_scan); scanButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { doDiscovery();/*from w ww .j a v a 2s . c o m*/ v.setVisibility(View.GONE); } }); mPairedDevicesArrayAdapter = 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(mPairedDevicesArrayAdapter); pairedListView.setOnItemClickListener(mDeviceClickListener); 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); mBtAdapter = BluetoothAdapter.getDefaultAdapter(); Set<BluetoothDevice> pairedDevices = mBtAdapter.getBondedDevices(); boolean empty = true; if (pairedDevices.size() > 0) { for (BluetoothDevice device : pairedDevices) { if ((device.getBluetoothClass() != null) && (device.getBluetoothClass().getDeviceClass() == BluetoothClass.Device.TOY_ROBOT)) { mPairedDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress()); empty = false; } } } if (!empty) { findViewById(R.id.title_paired_devices).setVisibility(View.VISIBLE); findViewById(R.id.no_devices).setVisibility(View.GONE); } if (checkPlayService()) { Intent intent = new Intent(this, RegistrationIntentService.class); startService(intent); } }