Example usage for android.bluetooth BluetoothDevice getName

List of usage examples for android.bluetooth BluetoothDevice getName

Introduction

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

Prototype

@RequiresPermission(Manifest.permission.BLUETOOTH)
public String getName() 

Source Link

Document

Get the friendly Bluetooth name of the remote device.

Usage

From source file:co.aurasphere.bluepair.bluetooth.BluetoothController.java

/**
 * Converts a BluetoothDevice to its String representation.
 *
 * @param device the device to convert to String.
 * @return a String representation of the device.
 *///  ww  w .  j  a  va  2 s.c  om
public static String deviceToString(BluetoothDevice device) {
    return "[Address: " + device.getAddress() + ", Name: " + device.getName() + "]";
}

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

/**
 * Restituisce il nome di un dispositivo.
 * //from   www  .  j av  a2 s  .c  o 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

public static ArrayList<ParcelUuid> getDeviceUuids(BluetoothDevice device) {
    ArrayList<ParcelUuid> result = new ArrayList<ParcelUuid>();

    try {/*from  ww w  .j a va  2 s  . co m*/
        Method method = device.getClass().getMethod("getUuids", null);
        ParcelUuid[] phoneUuids = (ParcelUuid[]) method.invoke(device, null);
        if (phoneUuids != null) {
            for (ParcelUuid uuid : phoneUuids) {
                if (D)
                    Log.d(TAG, device.getName() + ": " + uuid.toString());
                result.add(uuid);
            }
        }
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
        if (D)
            Log.e(TAG, "getDeviceUuids() failed", e);
    } catch (InvocationTargetException e) {
        e.printStackTrace();
        if (D)
            Log.e(TAG, "getDeviceUuids() failed", e);
    } catch (IllegalAccessException e) {
        e.printStackTrace();
        if (D)
            Log.e(TAG, "getDeviceUuids() failed", e);
    }

    return result;
}

From source file:Main.java

/**
 * Populates the device names and the device addresses with all the suitable
 * bluetooth devices./*from  w  w w  .ja v  a2s  . c  om*/
 * 
 * @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.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);//from ww w .  j a v a2  s. c  om

    } 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:com.moto.miletus.application.ble.neardevice.NearDeviceHolder.java

/**
 * onBleResolved/* w w w  . j a v  a2  s.c  o  m*/
 *
 * @param device BluetoothDevice
 * @param rssi   rssi
 */
@Override
public void onBleResolved(final BluetoothDevice device, final int rssi) {

    if (device.getName().contains(com.moto.miletus.utils.Strings.mSearchNameBle)) {
        list.add(new Pair<>(device, (double) rssi));
    }

    if ((System.currentTimeMillis() - timeStamp) >= SEGS) {
        Log.i(TAG, "Delta: " + (System.currentTimeMillis() - timeStamp) / 1000 + "s");

        whoWins();

        clear();
    }
}

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 {/* w  w  w.j  a va  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: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);/* w  w w  .jav a  2  s .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:cz.cvut.sedekpav.cordova.bleplugin.BLEPlugin.java

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    try {//from  w  w w .java2s  . 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.fastbootmobile.encore.app.fragments.SettingsFragment.java

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

    getPreferenceManager().setSharedPreferencesName(SettingsKeys.PREF_SETTINGS);

    // Load the preferences from an XML resource
    addPreferencesFromResource(R.xml.settings);

    // Load Bluetooth paired devices
    final ListPreference btNameList = (ListPreference) findPreference(
            SettingsKeys.KEY_BLUETOOTH_AUTOCONNECT_NAME);
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();

    if (adapter == null) {
        // No Bluetooth adapter, remove preferences
        getPreferenceScreen().removePreference(findPreference(SettingsKeys.KEY_BLUETOOTH_AUTOCONNECT_ENABLE));
        getPreferenceScreen().removePreference(findPreference(SettingsKeys.KEY_BLUETOOTH_AUTOCONNECT_ACTION));
        getPreferenceScreen().removePreference(findPreference(SettingsKeys.KEY_BLUETOOTH_AUTOCONNECT_NAME));
        getPreferenceScreen().removePreference(findPreference("category_bluetooth"));
    } else {/*  w  w  w  . j a  v  a  2 s. co m*/
        Set<BluetoothDevice> pairedDevices = adapter.getBondedDevices();
        CharSequence[] entries = new CharSequence[pairedDevices.size()];

        String currentPreferred = getPrefs().getString(SettingsKeys.KEY_BLUETOOTH_AUTOCONNECT_NAME, null);

        int i = 0;
        for (BluetoothDevice device : pairedDevices) {
            entries[i] = device.getName();
            ++i;
        }
        btNameList.setEntries(entries);
        btNameList.setEntryValues(entries);

        if (currentPreferred != null) {
            btNameList.setDefaultValue(currentPreferred);
        }
    }
}