TARGET
Discovery of all available Bluetooth devices, such as my iPad, with bluetooth enabled (available for discovery).
ANDROID VERSION
6.0
PROBLEM
Unable to open Bluetooth devices.
CODE
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
public BroadcastReceiver mReceiver;
public IntentFilter filter;
private boolean discover_AvailableBluetoothDevice() {
mReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "onReceive Called");
String action = intent.getAction();
if (BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(action)) {
Log.d(TAG, "ACTION_DISCOVERY_STARTED");
} else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
Log.d(TAG, "ACTION_DISCOVERY_FINISHED");
} else if (BluetoothDevice.ACTION_FOUND.equals(action)) {
Log.d(TAG, "ACTION_FOUND");
BluetoothDevice device = (BluetoothDevice) intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
String str = device.getName() + "\n( " + device.getAddress() + " )";
adapter.add(str);
}
}
};
filter = new IntentFilter();
filter.addAction(BluetoothDevice.ACTION_FOUND);
filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED);
filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
registerReceiver(mReceiver, filter);
boolean isSuccessDiscovery = mBluetoothAdapter.startDiscovery();
return isSuccessDiscovery;
}
EXECUTION OF RESULTS (logcat)
02-02 01:17:26.142 7194-7194/eie.imt.smartswitch D/†MainActivity: This device support Bluetooth.
02-02 01:17:55.052 7194-7194/eie.imt.smartswitch D/†ConnectSwitchActivity: isSuccessDiscovery=true
02-02 01:17:55.147 7194-7194/eie.imt.smartswitch D/†ConnectSwitchActivity: onReceive Called
02-02 01:17:55.147 7194-7194/eie.imt.smartswitch D/†ConnectSwitchActivity: ACTION_DISCOVERY_STARTED
02-02 01:18:07.909 7194-7194/eie.imt.smartswitch D/†ConnectSwitchActivity: onReceive Called
02-02 01:18:07.910 7194-7194/eie.imt.smartswitch D/†ConnectSwitchActivity: ACTION_DISCOVERY_FINISHED
I see that the program is not included in the ACTION_FOUND condition block , but my bluetooth iPad is on, where does the problem arise?
source
share