2016-06-06 2 views
5

Je travaille avec une application qui recherche à proximité bluetooth. J'utilise les codes suivants, cela fonctionne trouver dans 5.0 il renvoie les périphériques bluetooth à proximité, mais quand je teste dans 6.0.1 BluetoothDevice.ACTION_FOUND n'est pas appelé, seuls BluetoothAdapter.ACTION_DISCOVERY_STARTED et BluetoothAdapter.ACTION_DISCOVERY_FINISHED sont appelés.Recherche Bluetooth à proximité dans 6.0.1

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); 
    bluetoothAdapter = bluetoothManager.getAdapter(); 
    Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE); 
    discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION,0); 
    startActivity(discoverableIntent); 
} 
private final BroadcastReceiver bReciever = new BroadcastReceiver() { 
    public void onReceive(Context context, Intent intent) { 
     String action = intent.getAction(); 
     System.out.println(action); 
     if (BluetoothDevice.ACTION_FOUND.equals(action)) { 
      BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); 
      System.out.println(device); 
     } 
    } 
}; 
public void onSearch(View v){ 
    if (bluetoothAdapter.isDiscovering()) { 
     bluetoothAdapter.cancelDiscovery(); 
    } 
    System.out.println(bluetoothAdapter.startDiscovery()); 
    IntentFilter intentFilter = new IntentFilter(); 
    intentFilter.addAction(BluetoothDevice.ACTION_FOUND); 
    intentFilter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED); 
    intentFilter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED); 
    registerReceiver(bReciever, intentFilter); 

} 

Ma question est pourquoi le BluetoothDevice.ACTION_FOUND n'a pas été appelé en 6.0.1? Je vous remercie.

+0

Avez-vous trouvé la cause. J'ai le même problème – Anu

Répondre

-1

avez-vous vérifié l'autorisation dans Application Manager?

Aller à "Réglages " -> "Apps" -> "votre application" -> "Permission".

et vérifiez si la permission bluetooth est donnée.

+0

Il n'y a aucune demande d'autorisation dans Mes autorisations de configuration d'applications. Dans Mon manifeste, j'ajoute les utilisations-permission suivantes