/** * Set filter on device address. * * @param deviceAddress The device Bluetooth address for the filter. It needs to be in the * format of "01:02:03:AB:CD:EF". The device address can be validated using * {@link BluetoothAdapter#checkBluetoothAddress}. * @throws IllegalArgumentException If the {@code deviceAddress} is invalid. */ public ScanFilter.Builder setDeviceAddress(String deviceAddress) { if (deviceAddress != null && !BluetoothAdapter.checkBluetoothAddress(deviceAddress)) { throw new IllegalArgumentException("invalid device address " + deviceAddress); } mDeviceAddress = deviceAddress; return this; }
private void connectDevice(String mac, IErrorListener listener) { if (mac == null || TextUtils.isEmpty(mac)) throw new IllegalArgumentException("mac address is null or empty!"); if (!BluetoothAdapter.checkBluetoothAddress(mac)) throw new IllegalArgumentException("mac address is not correct! make sure it's upper case!"); ConnectDeviceRunnable connectDeviceRunnable = new ConnectDeviceRunnable(mac, listener); checkNotNull(mExecutorService); mExecutorService.submit(connectDeviceRunnable); }
@Override public boolean checkBluetoothAddress(final String address) { return BluetoothAdapter.checkBluetoothAddress(address); }
@Override public boolean checkBluetoothAddress(final String address) { return BluetoothAdapter.checkBluetoothAddress(address); }
/** * Set filter on device address. * * @param deviceAddress The device Bluetooth address for the filter. It needs to be in the * format of "01:02:03:AB:CD:EF". The device address can be validated using * {@link BluetoothAdapter#checkBluetoothAddress}. * @throws IllegalArgumentException If the {@code deviceAddress} is invalid. */ public Builder setDeviceAddress(String deviceAddress) { if (deviceAddress != null && !BluetoothAdapter.checkBluetoothAddress(deviceAddress)) { throw new IllegalArgumentException("invalid device address " + deviceAddress); } mDeviceAddress = deviceAddress; return this; }
/** * Validates a MAC address. * * @param mac the mac address to validate * @return true if it's a valid address, otherwise false */ public static boolean isMacValid(@NonNull String mac) { return BluetoothAdapter.checkBluetoothAddress(mac.toUpperCase()); }
/** * Set filter on device address. * * @param deviceAddress The device Bluetooth address for the filter. It needs to be in the * format of "01:02:03:AB:CD:EF". The device address can be validated using * {@link BluetoothAdapter#checkBluetoothAddress}. * @throws IllegalArgumentException If the {@code deviceAddress} is invalid. */ public Builder setDeviceAddress(@NonNull final String deviceAddress) { //noinspection ConstantConditions if (deviceAddress != null && !BluetoothAdapter.checkBluetoothAddress(deviceAddress)) { throw new IllegalArgumentException("invalid device address " + deviceAddress); } this.deviceAddress = deviceAddress; return this; }
private void setAddress(String address) throws DataSourceResourceException { if (address != null && !BluetoothAdapter.checkBluetoothAddress(address)) { throw new DataSourceResourceException("\"" + address + "\" is not a valid MAC address"); } mExplicitAddress = address; }
@Override public void onTextChanged(CharSequence s, int start, int before, int count) { if(callbacks != null) callbacks.onMacChanged(s.toString().toUpperCase()); if(errorView != null) errorView.setVisibility(s != null && BluetoothAdapter.checkBluetoothAddress(s.toString().toUpperCase()) ? View.INVISIBLE : View.VISIBLE); }
@Override public void onTextChanged(CharSequence s, int start, int before, int count) { alertdialog.getButton(DialogInterface.BUTTON_POSITIVE) .setEnabled(BluetoothAdapter.checkBluetoothAddress(s.toString().toUpperCase())); }
@Override public void onMacChanged(String mac) { enteredMAC = mac; next.setEnabled( pager.getCurrentItem() != getCount() - 1 || (enteredMAC != null && BluetoothAdapter.checkBluetoothAddress(enteredMAC.toUpperCase()))); } });
/** * Add a MAC address to the filter list and enables filtering of events by device MAC address. * * @param address device mac address. If the address is not valid {@link IllegalArgumentException} * will be thrown. * * @return this builder instance. */ public ScanBuilder addDeviceAddress(String address) { if (!BluetoothAdapter.checkBluetoothAddress(address)) { throw new IllegalArgumentException("Invalid address:" + address); } scannerConfiguration.addDeviceAddress(address); return this; } }
@Override public void onClick(View v) { /*if (pagingTimer != null) pagingTimer.cancel(); pagingTimer = new Timer(); pagingTimer.schedule(new TimerTask() { @Override public void run() { setAutopage(); } }, AUTO_PAGE_RETURN_DELAY);*/ if (Build.VERSION.SDK_INT >= 23 && pager.getCurrentItem() == pager.getAdapter().getCount() - 1) { if(enteredMAC != null && BluetoothAdapter.checkBluetoothAddress(enteredMAC)) { org.denovogroup.murmur.backend.SecurityManager.setStoredMAC(WelcomeActivity.this, enteredMAC); goToMain(); } else { next.setEnabled(false); return; } } changePageRunnable.run(); } });
public Set<BluetoothDevice> getCandidateDevices() { Set<BluetoothDevice> candidates = new HashSet<>(); for (BluetoothDevice device : getPairedDevices()) { if (device.getName().startsWith( BluetoothVehicleInterface.DEVICE_NAME_PREFIX)) { candidates.add(device); } } SharedPreferences preferences = mContext.getSharedPreferences(KNOWN_BLUETOOTH_DEVICE_PREFERENCES, Context.MODE_MULTI_PROCESS); Set<String> detectedDevices = SupportSettingsUtils.getStringSet( preferences, KNOWN_BLUETOOTH_DEVICE_PREF_KEY, new HashSet<String>()); for (String address : detectedDevices) { if (BluetoothAdapter.checkBluetoothAddress(address)) { candidates.add(getDefaultAdapter().getRemoteDevice(address)); } } for (BluetoothDevice candidate : candidates) { Log.d(TAG, "Found previously discovered or paired OpenXC BT VI " + candidate.getAddress()); } return candidates; }
private void invokeConnectToBluetoothDevice() { final OpenScale openScale = OpenScale.getInstance(); if (openScale.getSelectedScaleUserId() == -1) { showNoSelectedUserDialog(); return; } String deviceName = prefs.getString( BluetoothPreferences.PREFERENCE_KEY_BLUETOOTH_DEVICE_NAME, ""); String hwAddress = prefs.getString( BluetoothPreferences.PREFERENCE_KEY_BLUETOOTH_HW_ADDRESS, ""); if (!BluetoothAdapter.checkBluetoothAddress(hwAddress)) { setBluetoothStatusIcon(R.drawable.ic_bluetooth_connection_lost); Toast.makeText(getApplicationContext(), R.string.info_bluetooth_no_device_set, Toast.LENGTH_SHORT).show(); return; } BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE); if (!bluetoothManager.getAdapter().isEnabled()) { setBluetoothStatusIcon(R.drawable.ic_bluetooth_connection_lost); Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, ENABLE_BLUETOOTH_REQUEST); return; } Toast.makeText(getApplicationContext(), getResources().getString(R.string.info_bluetooth_try_connection) + " " + deviceName, Toast.LENGTH_SHORT).show(); setBluetoothStatusIcon(R.drawable.ic_bluetooth_searching); if (!openScale.connectToBluetoothDevice(deviceName, hwAddress, callbackBtHandler)) { setBluetoothStatusIcon(R.drawable.ic_bluetooth_connection_lost); Toast.makeText(getApplicationContext(), deviceName + " " + getResources().getString(R.string.label_bt_device_no_support), Toast.LENGTH_SHORT).show(); } }
if(mac != null && mac.length() > 0){ macEditText.setText(mac); macEditText.setTextColor(getResources().getColor(BluetoothAdapter.checkBluetoothAddress(mac) ? android.R.color.black : android.R.color.holo_red_dark)); } else { macEditText.clearComposingText();