List of usage examples for android.bluetooth BluetoothDevice getName
@RequiresPermission(Manifest.permission.BLUETOOTH)
public String getName()
From source file:com.example.mego.adas.bluetooth.ConnectFragment.java
/** * get the paired devices in the phone//ww w . ja v a 2s .c om */ 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:com.diy.blelib.profile.BleProfileService.java
@Override public int onStartCommand(final Intent intent, final int flags, final int startId) { if (intent == null || !intent.hasExtra(EXTRA_DEVICE_ADDRESS)) throw new UnsupportedOperationException("No device address at EXTRA_DEVICE_ADDRESS key"); mDeviceAddress = intent.getStringExtra(EXTRA_DEVICE_ADDRESS); Log.i(TAG, "Service started"); //?????//from w w w.java2 s .c om if (!mBlutoothAdapter.isEnabled()) mBlutoothAdapter.enable(); // notify user about changing the state to CONNECTING final Intent broadcast = new Intent(BROADCAST_CONNECTION_STATE); broadcast.putExtra(EXTRA_CONNECTION_STATE, STATE_CONNECTING); LocalBroadcastManager.getInstance(BleProfileService.this).sendBroadcast(broadcast); final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE); final BluetoothAdapter adapter = bluetoothManager.getAdapter(); final BluetoothDevice device = adapter.getRemoteDevice(mDeviceAddress); mDeviceName = device.getName(); onServiceStarted(); Log.v(TAG, "Connecting..."); mBleManager.connect(BleProfileService.this, device); return START_REDELIVER_INTENT; }
From source file:iha_au.ppmonitor.Services.BleService.java
/** * Opretter forbindelse til HW-bluetooth modulets GATT server. * @param device Det fundne device fra LeScanCallBack. *//*from w w w. j ava2 s.co m*/ private void connecToGatt(BluetoothDevice device) { Log.v("DEBUG", "Get device name: " + device.getName()); bGatt = device.connectGatt(getApplicationContext(), false, gattCallBack); }
From source file:org.deviceconnect.android.deviceplugin.sphero.SpheroDeviceService.java
@Override public void onCreate() { super.onCreate(); EventManager.INSTANCE.setController(new MemoryCacheController()); SpheroManager.INSTANCE.setService(this); registerBluetoothFilter();/*from w w w. j av a2 s .c om*/ registerDConnectServiceFilter(); addProfile(new SpheroServiceDiscoveryProfile(getServiceProvider())); getServiceProvider().addServiceListener(this); //?Sphero???????? BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); Set<BluetoothDevice> pairedDevices = adapter.getBondedDevices(); for (BluetoothDevice device : pairedDevices) { if (device.getName() != null && device.getName().contains("Sphero")) { PermissionUtility.requestPermissions(SpheroDeviceService.this, mHandler, BleUtils.BLE_PERMISSIONS, new PermissionUtility.PermissionRequestCallback() { @Override public void onSuccess() { SpheroManager.INSTANCE.setDiscoveryListener(SpheroDeviceService.this); SpheroManager.INSTANCE.startDiscovery(SpheroDeviceService.this); } @NonNull @Override public void onFail(final String deniedPermission) { } }); break; } } }
From source file:com.duy.pascal.interperter.libraries.android.connection.bluetooth.AndroidBluetoothLib.java
@SuppressWarnings("unused") @PascalMethod(description = "Queries a remote device for it's name or null if it can't be resolved") public String bluetoothGetRemoteDeviceName( @PascalParameter(name = "address", description = "Bluetooth Address For Target Device") String address) { try {/*from ww w . j av a 2 s . c o m*/ BluetoothDevice mDevice; mDevice = mBluetoothAdapter.getRemoteDevice(address); return mDevice.getName(); } catch (Exception e) { return null; } }
From source file:com.hardwarebreakout.bleboosterdemo.DeviceScanActivity.java
@Override protected void onListItemClick(ListView l, View v, int position, long id) { final BluetoothDevice device = mLeDeviceListAdapter.getDevice(position); if (device == null) return;/* w ww. ja v a2s .c om*/ Intent resultIntent = new Intent(); resultIntent.putExtra(NavigationActivity.EXTRAS_DEVICE_NAME, device.getName()); resultIntent.putExtra(NavigationActivity.EXTRAS_DEVICE_ADDRESS, device.getAddress()); setResult(Activity.RESULT_OK, resultIntent); finish(); // final Intent intent = new Intent(this, DeviceControlActivity.class); // intent.putExtra(DeviceControlActivity.EXTRAS_DEVICE_NAME, device.getName()); // intent.putExtra(DeviceControlActivity.EXTRAS_DEVICE_ADDRESS, device.getAddress()); // if (mScanning) { // mBluetoothAdapter.stopLeScan(mLeScanCallback); // mScanning = false; // } // startActivity(intent); }
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() + ")"); }//w w w .j a va2s. 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 ww w .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); } }
From source file:com.example.shahrukhqasim2.deepmount.DeviceScanActivity.java
@Override protected void onListItemClick(ListView l, View v, int position, long id) { final BluetoothDevice device = mLeDeviceListAdapter.getDevice(position); if (device == null) return;/*w w w . j a v a 2 s.co m*/ final Intent intent = new Intent(this, MainActivity.class); intent.putExtra(MainActivity.EXTRAS_DEVICE_NAME, device.getName()); intent.putExtra(MainActivity.EXTRAS_DEVICE_ADDRESS, device.getAddress()); if (mScanning) { mBluetoothAdapter.stopLeScan(mLeScanCallback); mScanning = false; } startActivity(intent); }
From source file:uk.ac.horizon.ubihelper.service.channel.BluetoothDiscoveryChannel.java
protected synchronized void handlePollComplete() { if (pollInProgress) pollComplete();//from ww w . j av a 2s . 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 } }