Example usage for android.bluetooth BluetoothAdapter getBondedDevices

List of usage examples for android.bluetooth BluetoothAdapter getBondedDevices

Introduction

In this page you can find the example usage for android.bluetooth BluetoothAdapter getBondedDevices.

Prototype

@RequiresPermission(Manifest.permission.BLUETOOTH)
public Set<BluetoothDevice> getBondedDevices() 

Source Link

Document

Return the set of BluetoothDevice objects that are bonded (paired) to the local adapter.

Usage

From source file:it.scoppelletti.mobilepower.preference.BTDevicePreference.java

public void run(BluetoothAdapter adapter) {
    int i, n;/* w  ww  . j  a va  2  s  . c  o m*/
    CharSequence[] entries, entryValues;
    Set<BluetoothDevice> devices;

    devices = adapter.getBondedDevices();
    n = devices.size();
    if (n > 0) {
        entries = new CharSequence[n];
        entryValues = new CharSequence[n];
        i = 0;
        for (BluetoothDevice device : devices) {
            entries[i] = BTManager.getName(device);
            entryValues[i] = device.getAddress();
            i++;
        }
    } else {
        entries = new CharSequence[1];
        entryValues = new CharSequence[1];

        entries[0] = getContext().getText(R.string.lbl_BTNoDevicePaired);
        entryValues[0] = StringUtils.EMPTY;
    }

    setEntries(entries);
    setEntryValues(entryValues);
}

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 .  j  a  v a  2  s  .c o  m
    return null;
}

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  ww.j  a v a  2  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:com.pileproject.drive.setting.machine.BluetoothMachineSelectFragment.java

private void updatePairedList() {
    BluetoothMachineListAdapter listAdapter = (BluetoothMachineListAdapter) mPairedDevicesListView.getAdapter();
    BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    listAdapter.clear();/*from  www .j  a va2  s .  c  om*/
    listAdapter.addAll(bluetoothAdapter.getBondedDevices());

    String macAddress = MachinePreferences.get(getActivity()).getMacAddress();

    if (BluetoothAdapter.checkBluetoothAddress(macAddress)) {
        BluetoothDevice device = bluetoothAdapter.getRemoteDevice(macAddress);

        if (listAdapter.contains(device)) {
            mPairedDevicesListView.setItemChecked(listAdapter.getPosition(device), true);
        }
    }
}

From source file:com.mattprecious.notisync.fragment.DeviceListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.device_list, container, false);

    BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
    if (btAdapter == null) {
        return super.onCreateView(inflater, container, savedInstanceState);
    }/*w  ww  .j  a v  a 2 s .  co  m*/

    localDeviceSet = Sets.newHashSet(Preferences.getDevices(getActivity()));

    listAdapter = new DeviceAdapter(getActivity(), Lists.newArrayList(btAdapter.getBondedDevices()));

    deviceList = (ListView) rootView.findViewById(R.id.deviceList);
    deviceList.setAdapter(listAdapter);

    return rootView;
}

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();
            }//from  w  w  w .  j a  v a  2 s.c om
            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.mattprecious.notisync.preferences.DevicePreferenceFragment.java

@Override
public void onResume() {
    super.onResume();

    BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
    if (btAdapter == null) {
        return;/*from w  ww . ja va 2 s  . 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.deviceconnect.android.deviceplugin.sphero.SpheroDeviceService.java

@Override
public void onCreate() {
    super.onCreate();

    EventManager.INSTANCE.setController(new MemoryCacheController());
    SpheroManager.INSTANCE.setService(this);
    registerBluetoothFilter();//from ww w.j  a va 2  s.  c o m
    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.digitalobstaclecourse.bluefinder.FindCar.java

void insert_paired_devices_into_database() {
    BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if (mBluetoothAdapter == null) {
        showNoBluetoothDialog();/* w  w w.ja v a  2s  .  c  o  m*/
    }
    Set<BluetoothDevice> paired_devices = null;
    if (mBluetoothAdapter != null) {
        paired_devices = mBluetoothAdapter.getBondedDevices();
    }
    DataAccessModule dataAccess = DataAccessModule.getDataAccessModule(this);
    if (paired_devices != null) {
        for (BluetoothDevice d : paired_devices) {
            //Log.d(TAG, "msg" + d.getName());
            dataAccess.add_device(d);
        }
    } else {
        //Log.e(TAG, "paired_devices  == null");
    }
    dataAccess.add_event("Power Disconnect Location", "POWER");
    //Log.d(TAG, "Logging all devices");
}

From source file:com.sweetiepiggy.littlepro.LittleProActivity.java

private BluetoothDevice getBluetoothPair() {
    BluetoothDevice pairedDevice = null;
    BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if (bluetoothAdapter == null) {
        Toast.makeText(getApplicationContext(), new Error("Bluetooth not found").getMessage(),
                Toast.LENGTH_SHORT).show();
    } else if (!bluetoothAdapter.isEnabled()) {
        Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableBtIntent, ACTIVITY_ENABLE_BLUETOOTH);
    } else {/*from  w  w w.j a v  a  2 s  .com*/
        Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices();
        Toast.makeText(getApplicationContext(), pairedDevices.size() + " paired devices found",
                Toast.LENGTH_SHORT).show();
        switch (pairedDevices.size()) {
        case 0:
            //               bluetoothAdapter.startDiscovery();
            break;
        case 1:
            pairedDevice = pairedDevices.iterator().next();
            break;
        /* choose device */
        default:
            //               for (pd : pairedDevices) {
            //               }
            break;
        }
    }

    return pairedDevice;
}