BluetoothDevice.ACTION\发现在版本为Marshmallow的Android设备中不起作用
以下是我检测蓝牙相关操作的代码BluetoothDevice.ACTION\发现在版本为Marshmallow的Android设备中不起作用,android,bluetooth,redmi-device,Android,Bluetooth,Redmi Device,以下是我检测蓝牙相关操作的代码 private final BroadcastReceiver mReceiver = new BroadcastReceiver() { public void onReceive(Context context, Intent intent) { String action = intent.getAction(); Log.i(TAG, "-------------------Bluetooth Operation--
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());
}
}
};
它适用于大多数Android设备。但问题只存在于带有棉花糖的Android设备。它们不会返回BluetoothDevice。在找到新设备时,找到了ACTION_。我已正确注册了中提到的广播接收器
任何解决方案…?Sry对于重复的问题,我已找到此问题的结果,请参阅: