1
wanted to list all bluetooth devices in a list, but when I try to create a Arrayadapter the application hangs and gives this error
`
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.tela);
BluetoothAdapter adaptador = BluetoothAdapter.DefaultAdapter; // procura o adap. bluetooth padrão
ListView lista = FindViewById<ListView>(Resource.Id.list);
if (adaptador == null)
{
Toast.MakeText(this, "Esse aparelho não tem bluetooth", ToastLength.Long).Show();
}
else {
if (adaptador.IsEnabled == true)
{
ICollection<BluetoothDevice> aparelhos = adaptador.BondedDevices;
BluetoothDevice[] apa = new BluetoothDevice[aparelhos.Count];
ArrayAdapter<BluetoothDevice> adapconfig;
ParcelUuid[] uuid = new ParcelUuid[aparelhos.Count];
BluetoothSocket socket;
int i = 0;
foreach (BluetoothDevice aparelho in aparelhos)
{
apa[i] = aparelho;
uuid = aparelho.GetUuids();
socket = aparelho.CreateRfcommSocketToServiceRecord(uuid[i].Uuid);
i++;
}
adapconfig = new ArrayAdapter<BluetoothDevice>(this, Resource.Layout.tela, Resource.Id.list,apa);
lista.Adapter = adapconfig;
}
else{
Toast.MakeText(this,"Ative o bluetooth para continuar",ToastLength.Long);
}
}
}`
Try to use
BluetoothAdapter.getDefaultAdapter();
Andadaptador.getBondedDevices();
– Lennoard Silva