Bonsoir à tous !
Je voudrais pouvoir lister tous les périphériques bluetooth à portée.
Je sais comment lister ceux appairés mais pas tous ceux à portée.
Merci pour vôtre aide !![]()
Bonsoir à tous !
Je voudrais pouvoir lister tous les périphériques bluetooth à portée.
Je sais comment lister ceux appairés mais pas tous ceux à portée.
Merci pour vôtre aide !![]()
Bonjour,
Pour le bluetooth , pour savoir quel appareil sont à portée il suffit de faire un inquiry . Une fonctionnalité existe sur android (startDiscovery)
http://developer.android.com/referen...iscovery%28%29
Tu as aussi explication comment marche le bluetooth sur ce lien
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 // Create a BroadcastReceiver for ACTION_FOUND private final BroadcastReceiver mReceiver = new BroadcastReceiver() { public void onReceive(Context context, Intent intent) { String action = intent.getAction(); // When discovery finds a device if (BluetoothDevice.ACTION_FOUND.equals(action)) { // Get the BluetoothDevice object from the Intent BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); // Add the name and address to an array adapter to show in a ListView mArrayAdapter.add(device.getName() + "\n" + device.getAddress()); } } }; // Register the BroadcastReceiver IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND); registerReceiver(mReceiver, filter); // Don't forget to unregister during onDestroy
Bon voici mon code pour lister les périphériques Bluetooth appairés :
Je n'arrive pas à utiliser ce même code pour lister à la place, les téléphone à portée..
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.listscan); final Window win = getWindow(); win.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setTitle(" Appareils Détectés"); setTitleColor(Color.CYAN); mDevices = new ArrayList<String>(); aa = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,mDevices); aa.notifyDataSetChanged(); lst = (ListView)findViewById(R.id.lst); lst.setAdapter(aa); lst.setCacheColorHint(Color.TRANSPARENT); lst.setBackgroundColor(Color.TRANSPARENT); lst.setBackgroundResource(R.drawable.bg_scan); lst.setOnItemClickListener(this); bA = BluetoothAdapter.getDefaultAdapter(); Set<BluetoothDevice> pairedDevices = bA.getBondedDevices(); if (pairedDevices.size() > 0) { for (BluetoothDevice device : pairedDevices) { mDevices.add(device.getName() + "\n" + device.getAddress()); } } else { String noDevices = new String("Aucun prériphérique appairé"); mDevices.add(noDevices); }
Quand j'utilise le code donné plus haut, rien ne s'affiche(même si il y a 3 téléphones en bluetooth juste à côté...)
Voilà si quelqu'un peut m'aider...
Merci !
Bonjour,
Il y a une autorisation à avoir, peut être que le problème vient de là.Note: Android-powered devices are not discoverable by default. A user can make the device discoverable for a limited time through the system settings, or an application can request that the user enable discoverability without leaving the application. How to enable discoverability is discussed below.
Partager