This following is My Code to Detect Bluetooth Related Operations.
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.i(TAG, "-------------------Bluetooth Operation-----------------:");
if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {
final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
if (state == BluetoothAdapter.STATE_ON) {
Log.i(TAG, "-------------------BlueTooth ON-----------------");
}else if(state == BluetoothAdapter.STATE_OFF){
Log.i(TAG, "-------------------BlueTooth OFF-----------------");
}
} else if (BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(action)) {
Log.i(TAG, "-------------------BlueTooth Discover Started-----------------");
} else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
Log.i(TAG, "-------------------BlueTooth Discover Finished-----------------");
} else if (BluetoothDevice.ACTION_FOUND.equals(action)) {
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
Log.i(TAG, "-------------------New Device Found-----------------");
Log.i(TAG, "-------------------------NAME :" + device.getName());
Log.i(TAG, "-------------------------MAC ADDRESS :" + device.getAddress());
}
}
};
It Works Fine with Most of the Android Devices.But the Problem is Only with Android Devices with Marshmallow .They Doesn't Return BluetoothDevice.ACTION_FOUND when a new Device was Found.I have properly registered the Broadcast Receiver as Mentioned in the Developer Guide
Any Solutions...?