У меня проблема с приложением Android, подключающим модуль RN4020. Когда я создаю приложение на Samsung S7, у меня есть успех в подключении и передаче данных, но как только я пытаюсь сделать это с моей запиской, я не могу подключиться. Само устройство не видит ни одного телефона, подключенного при использовании Примечание 9. На модуле это светодиод подключения, который показывает, подключено ли устройство. При использовании S7 Bluetooth показывает соединение (индикатор включен), но в Note 9 индикатор выключен.
// Open a BluetoothGatt connection to a BLE device given its address
public boolean connect(final String address) {
if (mBluetoothAdapter == null || address == null) { //Check that we have a Bluetooth adappter and device address
Log.w(TAG, "BluetoothAdapter not initialized or unspecified address."); //Log a warning that something went wrong
return false; //Failed to connect
}
// Previously connected device. Try to reconnect.
if (mBluetoothDeviceAddress != null && address.equals(mBluetoothDeviceAddress)
&& mBluetoothGatt != null) {
Log.d(TAG, "Trying to use an existing mBluetoothGatt for connection.");
if (mBluetoothGatt.connect()) {
mConnectionState = STATE_CONNECTING;
return true;
} else {
return false;
}
}
final BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
if (device == null) {
Log.d(TAG, "Device not found. Unable to connect.");
return false;
}
// We want to directly connect to the device, so we are setting the autoConnect
// parameter to false.
mBluetoothGatt = device.connectGatt(this, false, mGattCallback);
Log.d(TAG, "Trying to create a new connection.");
mBluetoothDeviceAddress = address;
mConnectionState = STATE_CONNECTING;
return true;
}
введите описание изображения здесь введите описание изображения здесь
введите описание изображения здесь
// Open a BluetoothGatt connection to a BLE device given its address
public boolean connect(final String address) {
if (mBluetoothAdapter == null || address == null) { //Check that we have a Bluetooth adappter and device address
Log.w(TAG, "BluetoothAdapter not initialized or unspecified address."); //Log a warning that something went wrong
return false; //Failed to connect
}
// Previously connected device. Try to reconnect.
if (mBluetoothDeviceAddress != null && address.equals(mBluetoothDeviceAddress)
&& mBluetoothGatt != null) {
Log.d(TAG, "Trying to use an existing mBluetoothGatt for connection.");
if (mBluetoothGatt.connect()) {
mConnectionState = STATE_CONNECTING;
return true;
} else {
return false;
}
}
final BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
if (device == null) {
Log.d(TAG, "Device not found. Unable to connect.");
return false;
}
// We want to directly connect to the device, so we are setting the autoConnect
// parameter to false.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
mBluetoothGatt = device.connectGatt(this, false, mGattCallback, BluetoothDevice.TRANSPORT_LE);
} else {
mBluetoothGatt = device.connectGatt(this, false, mGattCallback);
}
Log.d(TAG, "Trying to create a new connection.");
mBluetoothDeviceAddress = address;
mConnectionState = STATE_CONNECTING;
return true;
}