List of usage examples for android.bluetooth BluetoothDevice getName
@RequiresPermission(Manifest.permission.BLUETOOTH)
public String getName()
From source file:com.wolkabout.hexiwear.activity.MainActivity.java
private void onBonded(BluetoothDevice device) { Log.i(TAG, "Successfully bonded to: " + device.getName()); if (!devicesStore.isRegistered(device)) { deviceRegistrationService.registerHexiwearDevice(device); } else if (device.getName().contains(OTAP_PREFIX)) { FirmwareSelectActivity_.intent(this).device(device).start(); } else {/*w w w . j a va 2 s .c om*/ ReadingsActivity_.intent(this).flags(Intent.FLAG_ACTIVITY_SINGLE_TOP).device(device).start(); } }
From source file:org.libreoffice.impressremote.communication.BluetoothServersFinder.java
private void addServer(BluetoothDevice aBluetoothDevice) { Server.Type aServerType = buildServerType(aBluetoothDevice); String aServerAddress = aBluetoothDevice.getAddress(); String aServerName = aBluetoothDevice.getName(); Server aServer = Server.newBluetoothInstance(aServerType, aServerAddress, aServerName); mServers.put(aServer.getAddress(), aServer); Intent bIntent = Intents.buildServersListChangedIntent(); LocalBroadcastManager.getInstance(mContext).sendBroadcast(bIntent); }
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;/* ww w.java2s. c om*/ } } 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:nodomain.freeyourgadget.gadgetbridge.devices.pebble.PebblePairingActivity.java
private GBDevice getMatchingParentDeviceFromDB(BluetoothDevice btDevice) { String expectedSuffix = btDevice.getName(); expectedSuffix = expectedSuffix.replace("Pebble-LE ", ""); expectedSuffix = expectedSuffix.replace("Pebble Time LE ", ""); expectedSuffix = expectedSuffix.substring(0, 2) + ":" + expectedSuffix.substring(2); LOG.info("will try to find a Pebble with BT address suffix " + expectedSuffix); GBDevice gbDevice = null;// w w w . j a v a 2 s. co m try (DBHandler dbHandler = GBApplication.acquireDB()) { DaoSession session = dbHandler.getDaoSession(); DeviceDao deviceDao = session.getDeviceDao(); Query<Device> query = deviceDao.queryBuilder().where(DeviceDao.Properties.Type.eq(1), DeviceDao.Properties.Identifier.like("%" + expectedSuffix)).build(); List<Device> devices = query.list(); if (devices.size() == 0) { GB.toast("Please pair your non-LE Pebble before pairing the LE one", Toast.LENGTH_SHORT, GB.INFO); returnToPairingActivity(); return null; } else if (devices.size() > 1) { GB.toast("Can not match this Pebble LE to a unique device", Toast.LENGTH_SHORT, GB.INFO); returnToPairingActivity(); return null; } DeviceHelper deviceHelper = DeviceHelper.getInstance(); gbDevice = deviceHelper.toGBDevice(devices.get(0)); gbDevice.setVolatileAddress(btDevice.getAddress()); } catch (Exception e) { GB.toast("Error retrieving devices from database", Toast.LENGTH_SHORT, GB.ERROR); returnToPairingActivity(); return null; } return gbDevice; }
From source file:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.activities.SensorSettingsActivity.java
private String getDeviceName(String deviceAddress) { BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); BluetoothDevice[] bondDevice = (BluetoothDevice[]) mBluetoothAdapter.getBondedDevices() .toArray(new BluetoothDevice[0]); for (BluetoothDevice bd : bondDevice) { if (bd.getAddress().equals(deviceAddress)) return bd.getName(); }/*from w w w .jav a 2 s .c o m*/ return null; }
From source file:jp.co.kayo.ykmjuku.andylib.DeviceListActivity.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Bundle args = getArguments();//from w ww . ja v a 2 s . co m 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// www. ja v a 2 s .c o m 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();/*www.j a v a 2 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.mattprecious.notisync.preferences.DevicePreferenceFragment.java
@Override public void onResume() { super.onResume(); BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter(); if (btAdapter == null) { return;/*from ww w .j a v a 2s .c o 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: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 av a 2 s . c o m } }