Example usage for android.bluetooth BluetoothDevice getAddress

List of usage examples for android.bluetooth BluetoothDevice getAddress

Introduction

In this page you can find the example usage for android.bluetooth BluetoothDevice getAddress.

Prototype

public String getAddress() 

Source Link

Document

Returns the hardware address of this BluetoothDevice.

Usage

From source file:it.scoppelletti.mobilepower.bluetooth.BTManager.java

/**
 * Restituisce il nome di un dispositivo.
 * //  w  ww .  jav  a2 s.co m
 * @param  device Dispositivo.
 * @return        Nome del dispositivo. Se il nome del dispositivo non 
 *                è determinabile, restituisce l’indirizzo del
 *                dispositivo.
 */
public static String getName(BluetoothDevice device) {
    String s;

    if (device == null) {
        throw new NullPointerException("Argument device is null.");
    }

    s = device.getName();
    if (StringUtils.isBlank(s)) {
        s = device.getAddress();
    }

    return s;
}

From source file:Main.java

/**
 * Populates the device names and the device addresses with all the suitable
 * bluetooth devices.//  ww w .j av  a2s. c  o  m
 * 
 * @param bluetoothAdapter the bluetooth adapter
 * @param deviceNames list of device names
 * @param deviceAddresses list of device addresses
 */
public static void populateDeviceLists(BluetoothAdapter bluetoothAdapter, List<String> deviceNames,
        List<String> deviceAddresses) {
    // Ensure the bluetooth adapter is not in discovery mode.
    bluetoothAdapter.cancelDiscovery();

    Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices();
    for (BluetoothDevice device : pairedDevices) {
        BluetoothClass bluetoothClass = device.getBluetoothClass();
        if (bluetoothClass != null) {
            // Not really sure what we want, but I know what we don't want.
            switch (bluetoothClass.getMajorDeviceClass()) {
            case BluetoothClass.Device.Major.COMPUTER:
            case BluetoothClass.Device.Major.PHONE:
                break;
            default:
                deviceAddresses.add(device.getAddress());
                deviceNames.add(device.getName());
            }
        }
    }
}

From source file:com.commonsware.android.bluetooth.rxecho.MainActivity.java

@Override
public void showDevice(BluetoothDevice device) {
    setTitle(getString(R.string.app_name) + " " + device.getAddress());

    getSupportFragmentManager().beginTransaction().hide(roster)
            .add(android.R.id.content, DeviceFragment.newInstance(device)).addToBackStack(null).commit();
}

From source file:cz.cvut.sedekpav.cordova.bleplugin.BLEPlugin.java

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    try {/*  www.  j  a  v a2s .com*/
        if (ACTION_LIST_DEVICES.equals(action)) {
            JSONObject arg_object = args.getJSONObject(0);
            BLE ble = new BLE(cordova.getActivity());
            /*            Intent calIntent = new Intent(Intent.ACTION_EDIT)
             .setType("vnd.android.cursor.item/event")
             .putExtra("beginTime", arg_object.getLong("startTimeMillis"))
             .putExtra("endTime", arg_object.getLong("endTimeMillis"))
             .putExtra("title", arg_object.getString("title"))
             .putExtra("description", arg_object.getString("description"))
             .putExtra("eventLocation", arg_object.getString("eventLocation"));
             this.cordova.getActivity().startActivity(calIntent);*/
            List<BluetoothDevice> devs = ble.listBluetoothDevices();

            JSONArray jArray = new JSONArray();
            for (BluetoothDevice dev : devs) {
                JSONObject json = new JSONObject();
                json.put("address", dev.getAddress().toString());
                json.put("name", dev.getName());
                jArray.put(json);
            }

            callbackContext.success(jArray);
            return true;
        }
        callbackContext.error("Invalid action");
        return false;
    } catch (Exception e) {
        System.err.println("Exception: " + e.getMessage());
        callbackContext.error(e.getMessage());
        return false;
    }
}

From source file:com.quadmeup.smartporttelemetrer.DeviceListAdapter.java

public View getView(int position, View convertView, final ViewGroup parent) {
    final ViewHolderPattern viewHolder;

    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.device_list, parent, false);

        viewHolder = new ViewHolderPattern();

        viewHolder.name = (TextView) convertView.findViewById(R.id.name);
        viewHolder.mac = (TextView) convertView.findViewById(R.id.mac);

        convertView.setTag(viewHolder);/* ww w.  j  a v  a  2 s .  c  o  m*/

    } else {
        viewHolder = (ViewHolderPattern) convertView.getTag();
    }

    final BluetoothDevice current = data.get(position);

    viewHolder.name.setText(current.getName());
    viewHolder.mac.setText(current.getAddress());

    convertView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            DataProvider dataProvider = new DataProvider(context);
            dataProvider.put(DataProvider.KEY_BT_MAC, current.getAddress());
            dataProvider.put(DataProvider.KEY_BT_NAME, current.getName());

            Toast.makeText(context, context.getResources().getString(R.string.bt_device_selected),
                    Toast.LENGTH_SHORT).show();
            NavUtils.navigateUpFromSameTask((Activity) context);
        }
    });

    return convertView;
}

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:com.wolkabout.hexiwear.service.DeviceDiscoveryService.java

private void onDeviceDiscovered(final BluetoothDeviceWrapper wrapper) {
    final BluetoothDevice device = wrapper.getDevice();
    Log.i(TAG, "Discovered device: " + device.getName() + "(" + device.getAddress() + ")");
    final String name = wrapper.getDevice().getName();
    if (HEXI_OTAP_TAG.equalsIgnoreCase(name)) {
        wrapper.setInOtapMode(true);/*  www  .  j  a  v a2s.co  m*/
    } else if (!HEXIWEAR_TAG.equalsIgnoreCase(name)) {
        return;
    }

    final Intent deviceDiscovered = new Intent(DEVICE_DISCOVERED);
    deviceDiscovered.putExtra(WRAPPER, Parcels.wrap(wrapper));
    sendBroadcast(deviceDiscovered);
}

From source file:com.example.multi_ndef.frag_bt.java

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

    btSpinner = (Spinner) v.findViewById(R.id.spinnerbt);
    btSpinner.setOnItemSelectedListener(this);
    ma = (CNFCInterface) getActivity().getApplication();
    try {/*from  ww  w .j av  a  2 s.c om*/
        BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

        Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices();

        if (pairedDevices.size() > 0) {
            for (BluetoothDevice device : pairedDevices) {
                String deviceBTName = device.getName();
                String address = device.getAddress();
                //String deviceBTMajorClass = getBTMajorDeviceClass(device.getBluetoothClass().getMajorDeviceClass());
                SpinnerArrayBT_Device_name.add(deviceBTName);
                SpinnerArrayBT_devices_mac.add(address);
            }
        }
    } catch (Exception e)
    //SpinnerArrayBT.a
    {

        Toast toast = Toast.makeText(getActivity().getApplicationContext(), "Bluetooth Code Error",
                Toast.LENGTH_SHORT);
        toast.show();

        int a1 = 10;
    }

    ArrayAdapter<String> btArrayAdapter = new ArrayAdapter<String>(this.getActivity(),
            android.R.layout.simple_spinner_item, SpinnerArrayBT_Device_name);
    btArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    btSpinner.setAdapter(btArrayAdapter);

    return v;
}

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  2s . c  om
    return null;
}

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

public void run(BluetoothAdapter adapter) {
    int i, n;/*from  w ww.j  a  v  a2  s . c  om*/
    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);
}