本文整理汇总了C++中QAndroidJniEnvironment::NewByteArray方法的典型用法代码示例。如果您正苦于以下问题:C++ QAndroidJniEnvironment::NewByteArray方法的具体用法?C++ QAndroidJniEnvironment::NewByteArray怎么用?C++ QAndroidJniEnvironment::NewByteArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QAndroidJniEnvironment
的用法示例。
在下文中一共展示了QAndroidJniEnvironment::NewByteArray方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: writeDescriptor
void QLowEnergyControllerPrivate::writeDescriptor(
const QSharedPointer<QLowEnergyServicePrivate> service,
const QLowEnergyHandle /*charHandle*/,
const QLowEnergyHandle descHandle,
const QByteArray &newValue)
{
Q_ASSERT(!service.isNull());
QAndroidJniEnvironment env;
jbyteArray payload;
payload = env->NewByteArray(newValue.size());
env->SetByteArrayRegion(payload, 0, newValue.size(),
(jbyte *)newValue.constData());
bool result = false;
if (hub) {
qCDebug(QT_BT_ANDROID) << "Write descriptor with handle " << descHandle
<< newValue.toHex() << "(service:" << service->uuid << ")";
result = hub->javaObject().callMethod<jboolean>("writeDescriptor", "(I[B)Z",
descHandle, payload);
}
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
env->ExceptionClear();
result = false;
}
env->DeleteLocalRef(payload);
if (!result)
service->setError(QLowEnergyService::DescriptorWriteError);
}
示例2: writeData
qint64 QBluetoothSocketPrivate::writeData(const char *data, qint64 maxSize)
{
//TODO implement buffered behavior (so far only unbuffered)
Q_Q(QBluetoothSocket);
if (state != QBluetoothSocket::ConnectedState || !outputStream.isValid()) {
qCWarning(QT_BT_ANDROID) << "Socket::writeData: " << state << outputStream.isValid();
errorString = QBluetoothSocket::tr("Cannot write while not connected");
q->setSocketError(QBluetoothSocket::OperationError);
return -1;
}
QAndroidJniEnvironment env;
jbyteArray nativeData = env->NewByteArray((qint32)maxSize);
env->SetByteArrayRegion(nativeData, 0, (qint32)maxSize, reinterpret_cast<const jbyte*>(data));
outputStream.callMethod<void>("write", "([BII)V", nativeData, 0, (qint32)maxSize);
env->DeleteLocalRef(nativeData);
emit q->bytesWritten(maxSize);
if (env->ExceptionCheck()) {
qCWarning(QT_BT_ANDROID) << "Error while writing";
env->ExceptionDescribe();
env->ExceptionClear();
errorString = QBluetoothSocket::tr("Error during write on socket.");
q->setSocketError(QBluetoothSocket::NetworkError);
return -1;
}
return maxSize;
}
示例3: writeToPort
qint64 QSerialPortPrivate::writeToPort(const char *data, qint64 maxSize)
{
if (deviceId == BAD_PORT)
{
q_ptr->setError(QSerialPort::NotOpenError);
return 0;
}
QAndroidJniEnvironment jniEnv;
jbyteArray jarrayL = jniEnv->NewByteArray(maxSize);
jniEnv->SetByteArrayRegion(jarrayL, 0, maxSize, (jbyte *)data);
if (jniEnv->ExceptionCheck())
jniEnv->ExceptionClear();
int resultL = QAndroidJniObject::callStaticMethod<jint>(
kJniClassName,
"write",
"(I[BI)I",
deviceId,
jarrayL,
internalWriteTimeoutMsec);
if (jniEnv->ExceptionCheck())
{
jniEnv->ExceptionClear();
q_ptr->setErrorString(QStringLiteral("Writing to the device threw an exception"));
jniEnv->DeleteLocalRef(jarrayL);
return 0;
}
jniEnv->DeleteLocalRef(jarrayL);
return resultL;
}
示例4: writeCharacteristic
void QLowEnergyControllerPrivate::writeCharacteristic(
const QSharedPointer<QLowEnergyServicePrivate> service,
const QLowEnergyHandle charHandle,
const QByteArray &newValue,
bool writeWithResponse)
{
//TODO don't ignore WriteWithResponse, right now we assume responses
Q_ASSERT(!service.isNull());
if (!service->characteristicList.contains(charHandle))
return;
QAndroidJniEnvironment env;
jbyteArray payload;
payload = env->NewByteArray(newValue.size());
env->SetByteArrayRegion(payload, 0, newValue.size(),
(jbyte *)newValue.constData());
bool result = false;
if (hub) {
qCDebug(QT_BT_ANDROID) << "Write characteristic with handle " << charHandle
<< newValue.toHex() << "(service:" << service->uuid
<< ", writeWithResponse:" << writeWithResponse << ")";
result = hub->javaObject().callMethod<jboolean>("writeCharacteristic", "(I[BI)Z",
charHandle, payload,
writeWithResponse ? QLowEnergyService::WriteWithResponse : QLowEnergyService::WriteWithoutResponse);
}
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
env->ExceptionClear();
result = false;
}
env->DeleteLocalRef(payload);
if (!result)
service->setError(QLowEnergyService::CharacteristicWriteError);
}