Code example for BluetoothDevice

Methods: getAddress, getName

0
    private BroadcastReceiver myReceiver = new BroadcastReceiver() {
        @Override 
        public void onReceive(Context context, Intent intent) { 
            Parcelable btParcel = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); 
            BluetoothDevice btDevice = (BluetoothDevice) btParcel; 
            arrayAdapter.add(btDevice.getName() + " - " + btDevice.getAddress()); 
        } 
    }; 
 
    @Override 
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        self = this;
        arrayAdapter = new ArrayAdapter<String>(self, R.layout.text);
        ListView lv = self.getListView();
        lv.setAdapter(arrayAdapter);
        lv.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                myBt.cancelDiscovery(); // Cancel BT discovery explicitly so
                // that connections can go through 
                String btDeviceInfo = ((TextView) arg1).getText().toString();