return NULL;
}
- // get BluetoothDevice method
- OIC_LOG(DEBUG, TAG, "get BluetoothDevice method");
- jmethodID jni_mid_connectGatt = CAGetJNIMethodID(env, "android/bluetooth/BluetoothDevice",
- "connectGatt",
- "(Landroid/content/Context;ZLandroid/"
- "bluetooth/BluetoothGattCallback;)"
- "Landroid/bluetooth/BluetoothGatt;");
- if (!jni_mid_connectGatt)
- {
- OIC_LOG(ERROR, TAG, "bleConnect: jni_mid_connectGatt is null");
- return NULL;
- }
+ jobject jni_obj_connectGatt = NULL;
+ jint jni_int_sdk = CALEGetBuildVersion(env);
+ OIC_LOG_V(INFO, TAG, "API level is %d", jni_int_sdk);
+ if (jni_int_sdk >= 23) // upper than API level 23
+ {
+ jmethodID jni_mid_connectGatt = CAGetJNIMethodID(env, "android/bluetooth/BluetoothDevice",
+ "connectGatt",
+ "(Landroid/content/Context;ZLandroid/"
+ "bluetooth/BluetoothGattCallback;I)"
+ "Landroid/bluetooth/BluetoothGatt;");
+ if (!jni_mid_connectGatt)
+ {
+ OIC_LOG(ERROR, TAG, "bleConnect: jni_mid_connectGatt is null");
+ return NULL;
+ }
- OIC_LOG(INFO, TAG, "CALL API - connectGatt");
- jobject jni_obj_connectGatt = (*env)->CallObjectMethod(env, bluetoothDevice,
- jni_mid_connectGatt,
- NULL,
- autoconnect, g_leGattCallback);
- if (!jni_obj_connectGatt)
- {
- OIC_LOG(ERROR, TAG, "connectGatt was failed..it will be removed");
- CACheckJNIException(env);
- CALEClientRemoveDeviceInScanDeviceList(env, jni_address);
- CALEClientUpdateSendCnt(env);
- return NULL;
+ jint jni_transport_le = CALEGetConstantsValue(env, CLASSPATH_BT_DEVICE, "TRANSPORT_LE");
+ OIC_LOG_V(INFO, TAG, "CALL API - connectGatt with transport LE(%d)", jni_transport_le);
+ jni_obj_connectGatt = (*env)->CallObjectMethod(env, bluetoothDevice,
+ jni_mid_connectGatt, NULL,
+ autoconnect, g_leGattCallback,
+ jni_transport_le);
+ if (!jni_obj_connectGatt)
+ {
+ OIC_LOG(ERROR, TAG, "connectGatt was failed..it will be removed");
+ CACheckJNIException(env);
+ CALEClientRemoveDeviceInScanDeviceList(env, jni_address);
+ CALEClientUpdateSendCnt(env);
+ return NULL;
+ }
+ else
+ {
+ OIC_LOG(DEBUG, TAG, "le connecting..please wait..");
+ }
}
- else
+ else // lower than API level 23
{
- OIC_LOG(DEBUG, TAG, "le connecting..please wait..");
+ jmethodID jni_mid_connectGatt = CAGetJNIMethodID(env, "android/bluetooth/BluetoothDevice",
+ "connectGatt",
+ "(Landroid/content/Context;ZLandroid/"
+ "bluetooth/BluetoothGattCallback;)"
+ "Landroid/bluetooth/BluetoothGatt;");
+ if (!jni_mid_connectGatt)
+ {
+ OIC_LOG(ERROR, TAG, "bleConnect: jni_mid_connectGatt is null");
+ return NULL;
+ }
+
+ OIC_LOG(INFO, TAG, "CALL API - connectGatt");
+ jni_obj_connectGatt = (*env)->CallObjectMethod(env, bluetoothDevice,
+ jni_mid_connectGatt,
+ NULL,
+ autoconnect, g_leGattCallback);
+ if (!jni_obj_connectGatt)
+ {
+ OIC_LOG(ERROR, TAG, "connectGatt was failed..it will be removed");
+ CACheckJNIException(env);
+ CALEClientRemoveDeviceInScanDeviceList(env, jni_address);
+ CALEClientUpdateSendCnt(env);
+ return NULL;
+ }
+ else
+ {
+ OIC_LOG(DEBUG, TAG, "le connecting..please wait..");
+ }
}
+
return jni_obj_connectGatt;
}