本文整理汇总了C++中QAndroidJniEnvironment::DeleteLocalRef方法的典型用法代码示例。如果您正苦于以下问题:C++ QAndroidJniEnvironment::DeleteLocalRef方法的具体用法?C++ QAndroidJniEnvironment::DeleteLocalRef怎么用?C++ QAndroidJniEnvironment::DeleteLocalRef使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QAndroidJniEnvironment
的用法示例。
在下文中一共展示了QAndroidJniEnvironment::DeleteLocalRef方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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);
}
示例3: 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;
}
示例4: registerNativeMethods
bool JniNative::registerNativeMethods()
{
JNINativeMethod methods[] {
{"notifyMsg", "(III)V", (void*)notifyMsg},
{"setDirectBuffer","(Ljava/lang/Object;I)V",(void*)setDirectBuffer}
};
const char *classname = "an/qt/useJar/ExtendsQtNative";
jclass clazz;
QAndroidJniEnvironment env;
QAndroidJniObject javaClass(classname);
clazz = env->GetObjectClass(javaClass.object<jobject>());
// QDBG << "find ExtendsQtNative - " << clazz;
bool result = false;
if (clazz) {
jint ret = env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0]));
env->DeleteLocalRef(clazz);
// QDBG << "RegisterNatives return - " << ret;
result = ret >= 0;
}
if (env->ExceptionCheck())
env->ExceptionClear();
return result;
}
示例5: registerNativeMethods
static bool registerNativeMethods()
{
JNINativeMethod methods[] {
{"OnImageCaptured", "(ILjava/lang/String;)V", (void*)onImageCaptured}
};
const char *classname = "an/qt/imageProcessor/ImageCaptureNative";
jclass clazz;
QAndroidJniEnvironment env;
QAndroidJniObject javaClass(classname);
clazz = env->GetObjectClass(javaClass.object<jobject>());
//clazz = env->FindClass(classname);
qDebug() << "find ImageCaptureNative - " << clazz;
bool result = false;
if(clazz)
{
jint ret = env->RegisterNatives(clazz,
methods,
sizeof(methods) / sizeof(methods[0]));
env->DeleteLocalRef(clazz);
qDebug() << "RegisterNatives return - " << ret;
result = ret >= 0;
}
if(env->ExceptionCheck()) env->ExceptionClear();
return result;
}
示例6: addToImageGallery
void Wpp::addToImageGallery(const QString& imageFullPath)
{
#if defined(Q_OS_ANDROID)
/*
http://stackoverflow.com/questions/2170214/image-saved-to-sdcard-doesnt-appear-in-androids-gallery-app
File imageFile = ...
MediaScannerConnection.scanFile(this, new String[] { imageFile.getPath() }, new String[] { "image/jpeg" }, null);
*/
QAndroidJniObject activity = QtAndroid::androidActivity();
qDebug() << __FUNCTION__ << "activity.isValid()=" << activity.isValid();
QAndroidJniEnvironment env;
//new String[] { imageFile.getPath() }
jobjectArray imageFilePaths = (jobjectArray)env->NewObjectArray(
1,
env->FindClass("java/lang/String"),
(jobject)0
);
QAndroidJniObject imagePathJString = QAndroidJniObject::fromString(imageFullPath);
env->SetObjectArrayElement(
imageFilePaths, 0, imagePathJString.object<jstring>() );
//new String[] { "image/jpeg", "image/png", "image/gif" }
jobjectArray imageFileTypes = (jobjectArray)env->NewObjectArray(
3,
env->FindClass("java/lang/String"),
(jobject)0
);
QAndroidJniObject imageType1 = QAndroidJniObject::fromString("image/jpeg");
env->SetObjectArrayElement(
imageFileTypes, 0, imageType1.object<jstring>() );
QAndroidJniObject imageType2 = QAndroidJniObject::fromString("image/png");
env->SetObjectArrayElement(
imageFileTypes, 1, imageType2.object<jstring>() );
QAndroidJniObject imageType3 = QAndroidJniObject::fromString("image/gif");
env->SetObjectArrayElement(
imageFileTypes, 2, imageType3.object<jstring>() );
QAndroidJniObject::callStaticMethod<void>("android/media/MediaScannerConnection",
"scanFile",
"(Landroid/content/Context;[Ljava/lang/String;[Ljava/lang/String;Landroid/media/MediaScannerConnection$OnScanCompletedListener;)V",
activity.object<jobject>(),
imageFilePaths, imageFileTypes, (jobject)0);
env->DeleteLocalRef(imageFilePaths);
env->DeleteLocalRef(imageFileTypes);
#else
#endif
}
示例7: onRegisterNativeMethods
void QQmlAndroidScrollView::onRegisterNativeMethods(jobject listener)
{
JNINativeMethod methods[] {{"onScrollChanged", "(JII)V", reinterpret_cast<void *>(onScrollChanged)}};
QAndroidJniEnvironment env;
jclass cls = env->GetObjectClass(listener);
env->RegisterNatives(cls, methods, sizeof(methods) / sizeof(methods[0]));
env->DeleteLocalRef(cls);
}
示例8: aseman_android_loclis_registerNativeMethods
bool aseman_android_loclis_registerNativeMethods() {
JNINativeMethod methods[] {{"_locationListened", "(DDDLjava/lang/String;)V", reinterpret_cast<void *>(locationListened)}};
QAndroidJniObject javaClass("land/aseman/android/extra/AsemanLocationListener");
QAndroidJniEnvironment env;
jclass objectClass = env->GetObjectClass(javaClass.object<jobject>());
env->RegisterNatives(objectClass, methods, sizeof(methods) / sizeof(methods[0]));
env->DeleteLocalRef(objectClass);
return true;
}
示例9: 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);
}
示例10: handleActivityResult
//.........这里部分代码省略.........
QString path(rawString);
qDebug() << "path[]=" << path;
paths.append(path);
env->ReleaseStringUTFChars(string, rawString);
}
emit this->accepted(paths);
}
else
{
QAndroidJniEnvironment env;
QAndroidJniObject uri = data.callObjectMethod("getData","()Landroid/net/Uri;");
qDebug() << __FUNCTION__ << "uri.isValid()=" << uri.isValid();
qDebug() << __FUNCTION__ << "uri=" << uri.toString();
/*
url is like: "content://media/external/images/media/87332"
for KitKat(android 4.4), uri is like: "content://com.android.providers.media.documents/document/image:3951"
*/
QAndroidJniObject activity = QtAndroid::androidActivity();
qDebug() << __FUNCTION__ << "activity.isValid()=" << activity.isValid();
QAndroidJniObject contentResolver = activity.callObjectMethod("getContentResolver","()Landroid/content/ContentResolver;");
qDebug() << __FUNCTION__ << "contentResolver.isValid()=" << contentResolver.isValid();
/*if ( receiverRequestCode == PICK_FROM_FILE_KITKAT )
{
jint Intent__FLAG_GRANT_READ_URI_PERMISSION = QAndroidJniObject::getStaticField<jint>(
"android.content.Intent", "FLAG_GRANT_READ_URI_PERMISSION");
jint Intent__FLAG_GRANT_WRITE_URI_PERMISSION = QAndroidJniObject::getStaticField<jint>(
"android.content.Intent", "FLAG_GRANT_WRITE_URI_PERMISSION");
jint takeFlags = data.callMethod<jint>("getFlags","()I");
takeFlags = takeFlags & ( Intent__FLAG_GRANT_READ_URI_PERMISSION | Intent__FLAG_GRANT_WRITE_URI_PERMISSION );
contentResolver.callMethod<void>("takePersistableUriPermission","(Landroid/net/Uri;I)V",
uri.object<jobject>(), takeFlags);
}*/
/*
String [] proj={MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(uri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
String path = cursor.getString(column_index);
cursor.close();
*/
QAndroidJniObject MediaStore_Images_Media_DATA
= QAndroidJniObject::getStaticObjectField(
"android/provider/MediaStore$MediaColumns", "DATA", "Ljava/lang/String;");
//"android/provider/MediaStore$Images$Media", "DATA", "Ljava/lang/String;");
qDebug() << "MediaStore_Images_Media_DATA.isValid()=" << MediaStore_Images_Media_DATA.isValid();
QAndroidJniObject nullObj;
jstring emptyJString = env->NewStringUTF("");
jobjectArray projection = (jobjectArray)env->NewObjectArray(
1,
env->FindClass("java/lang/String"),
emptyJString
);
jobject projection0 = env->NewStringUTF( MediaStore_Images_Media_DATA.toString().toStdString().c_str() );
env->SetObjectArrayElement(
projection, 0, projection0 );
// Cursor cursor = getContentResolver().query(uri, proj, null, null, null);
QAndroidJniObject cursor = contentResolver.callObjectMethod("query",
"(Landroid/net/Uri;[Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)Landroid/database/Cursor;",
uri.object<jobject>(), projection, nullObj.object<jstring>(), nullObj.object<jobjectArray>(), nullObj.object<jstring>());
qDebug() << __FUNCTION__ << "cursor.isValid()=" << cursor.isValid();
//int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
jint column_index = cursor.callMethod<jint>(
"getColumnIndexOrThrow","(Ljava/lang/String;)I", MediaStore_Images_Media_DATA.object<jstring>());
qDebug() << "column_index=" << column_index;
//cursor.moveToFirst();
cursor.callMethod<jboolean>("moveToFirst");
// String path = cursor.getString(column_index);
QAndroidJniObject path = cursor.callObjectMethod(
"getString",
"(I)Ljava/lang/String;", column_index );
qDebug() << __FUNCTION__ << "path.isValid()=" << path.isValid();
QString filePath = path.toString();
qDebug() << "filePath=" << filePath;
//cursor.close();
cursor.callMethod<jboolean>("close");
env->DeleteLocalRef(emptyJString);
env->DeleteLocalRef(projection);
env->DeleteLocalRef(projection0);
QStringList paths;
paths.append(filePath);
emit this->accepted(paths);
//m_imagePath = filePath;
//emit this->imagePathChanged();
}
}
}
示例11: managedQuery
//.........这里部分代码省略.........
//args, 0, env->NewStringUTF( QString().sprintf("%ld",thumbId).toStdString().c_str() ) );
args, 0, thumbIdJString );
// Cursor curThumb = managedQuery(Thumbnails.EXTERNAL_CONTENT_URI, null, Thumbnails._ID + "= ?", args, null);
QAndroidJniObject Images_Thumbnails__ID
= QAndroidJniObject::getStaticObjectField(
"android/provider/BaseColumns", "_ID", "Ljava/lang/String;");
qDebug() << "Images_Thumbnails__ID.isValid()=" << Images_Thumbnails__ID.isValid();
QAndroidJniObject selection=QAndroidJniObject::fromString( Images_Thumbnails__ID.toString() + "= ?" ); //path is valid
QAndroidJniObject curThumb = activity.callObjectMethod("managedQuery",
"(Landroid/net/Uri;[Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)Landroid/database/Cursor;",
Images_EXTERNAL_CONTENT_URI.object<jobject>(), nullObj.object<jobject>(),
selection.object<jstring>(), args, nullObj.object<jobject>()
);
qDebug() << "curThumb.isValid()=" << curThumb.isValid();
//if( curThumb.moveToFirst() ){
if ( curThumb.callMethod<jboolean>("moveToFirst") )
{
// String path = curThumb.getString(curThumb.getColumnIndex(Thumbnails.DATA));
QAndroidJniObject Images_Thumbnails_DATA
= QAndroidJniObject::getStaticObjectField(
"android/provider/MediaStore$Images$Thumbnails", "DATA", "Ljava/lang/String;");
qDebug() << "Images_Thumbnails_DATA.isValid()=" << Images_Thumbnails_DATA.isValid();
jint thumbDataColumn = curThumb.callMethod<jint>("getColumnIndex", "(Ljava/lang/String;)I", Images_Thumbnails_DATA.object<jstring>());
qDebug() << "thumbDataColumn = " << thumbDataColumn;
thumbData = cur.callObjectMethod("getString","(I)Ljava/lang/String;", thumbDataColumn );
qDebug() << "thumbData.isValid()=" << thumbData.isValid();
}
env->DeleteLocalRef(args);
env->DeleteLocalRef(thumbIdJString);
}
qDebug() << "_id=" << _id
<< ", bucketId=" << bucketId.toString()
<< ", bucket=" << bucket.toString()
<< ", date_taken=" << date.toString()
<< ", WxH=" << width.toString() << "x" << height.toString()
<< ", orientation=" << orientation
<< ", thumbId=" << thumbId.toString()
<< ", thumbData=" << thumbData.toString()
<< ", abs_path=" << mediaColumnsData.toString();
if ( !folderList.contains( bucketId.toString() ) )
{
qDebug() << "create folder:" << bucketId.toString();
GalleryFolder galleryFolder;
galleryFolder.setId( bucketId.toString() );
galleryFolder.setName( bucket.toString() );
folderList.insert(bucketId.toString(), galleryFolder);
}
wpp::qt::GalleryPhoto photo;
photo.setAbsolutePath( mediaColumnsData.toString() );
photo.setWidth( width.toString().toInt() );
photo.setHeight( height.toString().toInt() );
photo.setOrientation( orientation );
qDebug()<<"orientation===" << photo.getOrientation();
folderList[ bucketId.toString() ].addPhoto( photo );
}
while ( cur.callMethod<jboolean>("moveToNext") );
//while (cur.moveToNext());
示例12: handleActivityResult
void Gallery::handleActivityResult(int receiverRequestCode, int resultCode, const QAndroidJniObject & data)
{
int PICK_FROM_FILE = 1;
int SHOOT_PHOTO = 2;
jint Activity__RESULT_OK = QAndroidJniObject::getStaticField<jint>(
"android.app.Activity", "RESULT_OK");
if ( receiverRequestCode == PICK_FROM_FILE && resultCode == Activity__RESULT_OK )
{
QAndroidJniEnvironment env;
QAndroidJniObject uri = data.callObjectMethod("getData","()Landroid/net/Uri;");
qDebug() << __FUNCTION__ << "uri.isValid()=" << uri.isValid();
qDebug() << __FUNCTION__ << "uri=" << uri.toString();
/*
url is like: "content://media/external/images/media/87332"
*/
QAndroidJniObject activity = QtAndroid::androidActivity();
qDebug() << __FUNCTION__ << "activity.isValid()=" << activity.isValid();
QAndroidJniObject contentResolver = activity.callObjectMethod("getContentResolver","()Landroid/content/ContentResolver;");
qDebug() << __FUNCTION__ << "contentResolver.isValid()=" << contentResolver.isValid();
/*
String [] proj={MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(uri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
String path = cursor.getString(column_index);
cursor.close();
*/
QAndroidJniObject MediaStore_Images_Media_DATA
= QAndroidJniObject::getStaticObjectField(
"android/provider/MediaStore$MediaColumns", "DATA", "Ljava/lang/String;");
qDebug() << "MediaStore_Images_Media_DATA.isValid()=" << MediaStore_Images_Media_DATA.isValid();
QAndroidJniObject nullObj;
jstring emptyJString = env->NewStringUTF("");
jobjectArray projection = (jobjectArray)env->NewObjectArray(
1,
env->FindClass("java/lang/String"),
emptyJString
);
jobject projection0 = env->NewStringUTF( MediaStore_Images_Media_DATA.toString().toStdString().c_str() );
env->SetObjectArrayElement(
projection, 0, projection0 );
// Cursor cursor = getContentResolver().query(uri, proj, null, null, null);
QAndroidJniObject cursor = contentResolver.callObjectMethod("query",
"(Landroid/net/Uri;[Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)Landroid/database/Cursor;",
uri.object<jobject>(), projection, nullObj.object<jstring>(), nullObj.object<jobjectArray>(), nullObj.object<jstring>());
qDebug() << __FUNCTION__ << "cursor.isValid()=" << cursor.isValid();
//int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
jint column_index = cursor.callMethod<jint>(
"getColumnIndexOrThrow","(Ljava/lang/String;)I", MediaStore_Images_Media_DATA.object<jstring>());
qDebug() << "column_index=" << column_index;
//cursor.moveToFirst();
cursor.callMethod<jboolean>("moveToFirst");
// String path = cursor.getString(column_index);
QAndroidJniObject path = cursor.callObjectMethod(
"getString",
"(I)Ljava/lang/String;", column_index );
qDebug() << __FUNCTION__ << "path.isValid()=" << path.isValid();
QString filePath = path.toString();
//cursor.close();
cursor.callMethod<jboolean>("close");
env->DeleteLocalRef(emptyJString);
env->DeleteLocalRef(projection);
env->DeleteLocalRef(projection0);
/*
QAndroidJniObject inputStream = contentResolver.callObjectMethod(
"openInputStream","(Landroid/net/Uri;)Ljava/io/InputStream;", uri.object<jobject>());
qDebug() << __FUNCTION__ << "inputStream.isValid()=" << inputStream.isValid();
QStringList paths = QStandardPaths::standardLocations(QStandardPaths::DataLocation);
QDir dir( paths.first() );
QDir parentDir( dir.filePath("..") );
qDebug() << "parent path: " << parentDir.absolutePath();
if ( !dir.exists() )
{
qDebug() << "dir not exist, make it:" << dir;
qDebug() << "dir.name: " << dir.dirName();
qDebug() << "new make dir returns: " << parentDir.mkpath( dir.dirName() );
//qDebug() << "make dir returns: " << dir.mkdir(".");
}
QString pickFile = paths.first().append("/").append("PickFile");
QAndroidJniEnvironment env;
jbyteArray byteArray = env->NewByteArray(1024);
jint fileSize = inputStream.callMethod<jint>(
"available","()I");
qDebug() << "fileSize=" << fileSize;
QFile file( pickFile );
//.........这里部分代码省略.........