本文整理汇总了C++中QAndroidJniEnvironment::ExceptionDescribe方法的典型用法代码示例。如果您正苦于以下问题:C++ QAndroidJniEnvironment::ExceptionDescribe方法的具体用法?C++ QAndroidJniEnvironment::ExceptionDescribe怎么用?C++ QAndroidJniEnvironment::ExceptionDescribe使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QAndroidJniEnvironment
的用法示例。
在下文中一共展示了QAndroidJniEnvironment::ExceptionDescribe方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createVariantMap
static QVariantMap createVariantMap(jobject data) {
QVariantMap res;
QAndroidJniEnvironment env;
/* Reference : https://community.oracle.com/thread/1549999 */
// Get the HashMap Class
jclass jclass_of_hashmap = (env)->GetObjectClass(data);
// Get link to Method "entrySet"
jmethodID entrySetMethod = (env)->GetMethodID(jclass_of_hashmap, "entrySet", "()Ljava/util/Set;");
// Invoke the "entrySet" method on the HashMap object
jobject jobject_of_entryset = env->CallObjectMethod(data, entrySetMethod);
// Get the Set Class
jclass jclass_of_set = (env)->FindClass("java/util/Set"); // Problem during compilation !!!!!
if (jclass_of_set == 0) {
qWarning() << "java/util/Set lookup failed\n";
return res;
}
jclass jclass_of_string = env->FindClass("java/lang/String");
jclass jclass_of_integer = env->FindClass("java/lang/Integer");
jclass jclass_of_boolean = env->FindClass("java/lang/Boolean");
// Get link to Method "iterator"
jmethodID iteratorMethod = env->GetMethodID(jclass_of_set, "iterator", "()Ljava/util/Iterator;");
// Invoke the "iterator" method on the jobject_of_entryset variable of type Set
jobject jobject_of_iterator = env->CallObjectMethod(jobject_of_entryset, iteratorMethod);
// Get the "Iterator" class
jclass jclass_of_iterator = (env)->FindClass("java/util/Iterator");
// Get link to Method "hasNext"
jmethodID hasNextMethod = env->GetMethodID(jclass_of_iterator, "hasNext", "()Z");
jmethodID nextMethod = env->GetMethodID(jclass_of_iterator, "next", "()Ljava/lang/Object;");
while (env->CallBooleanMethod(jobject_of_iterator, hasNextMethod) ) {
QAndroidJniObject entry = env->CallObjectMethod(jobject_of_iterator,nextMethod);
QAndroidJniObject key = entry.callObjectMethod("getKey","()Ljava/lang/Object;");
QAndroidJniObject value = entry.callObjectMethod("getValue","()Ljava/lang/Object;");
QString k = key.toString();
if (!value.isValid())
continue;
if (env->IsInstanceOf(value.object<jobject>(),jclass_of_boolean)) {
res[k] = QVariant::fromValue<bool>(value.callMethod<jboolean>("booleanValue","()Z"));
} else if (env->IsInstanceOf(value.object<jobject>(),jclass_of_integer)) {
res[k] = value.callMethod<jint>("intValue","()I");
} else if (env->IsInstanceOf(value.object<jobject>(),jclass_of_string)) {
QString v = value.toString();
res[k] = v;
}
}
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
env->ExceptionClear();
}
// Delete local reference
return res;
}
示例2: managedQuery
//.........这里部分代码省略.........
QAndroidJniObject Images_EXTERNAL_CONTENT_URI
= QAndroidJniObject::getStaticObjectField(
"android/provider/MediaStore$Images$Media", "EXTERNAL_CONTENT_URI", "Landroid/net/Uri;");
qDebug() << "Images_EXTERNAL_CONTENT_URI.isValid()=" << Images_EXTERNAL_CONTENT_URI.isValid();
/*
// Make the query.
Cursor cur = managedQuery(Images_EXTERNAL_CONTENT_URI,
projection, // Which columns to return
"", // Which rows to return (all rows)
null, // Selection arguments (none)
"" // Ordering
);
*/
QAndroidJniObject activity = QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative", "activity", "()Landroid/app/Activity;");
qDebug() << "activity.isValid()=" << activity.isValid();
QAndroidJniObject contentResolver = activity.callObjectMethod("getContentResolver","()Landroid/content/ContentResolver;");
QAndroidJniObject emptyString=QAndroidJniObject::fromString(QString("")); //path is valid
qDebug() << "emptyString.isValid()=" << emptyString.isValid();
QAndroidJniObject nullObj;
QAndroidJniObject cur = 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>(), projection,
emptyString.object<jstring>(), nullObj.object<jobject>(), emptyString.object<jstring>()
);
qDebug() << "cur.isValid()=" << cur.isValid();
if (env->ExceptionCheck())
{
// Handle exception here.
qDebug() << "Exception when getting \"cur\"....";
env->ExceptionDescribe();
env->ExceptionClear();
}
QMap<QString, wpp::qt::GalleryFolder> folderList;
//if (cur.moveToFirst()) {
if ( cur.callMethod<jboolean>("moveToFirst") )
{
/*
int bucketColumn = cur.getColumnIndex(
MediaStore.Images.Media.BUCKET_DISPLAY_NAME);
*/
jint bucketColumn = cur.callMethod<jint>("getColumnIndex", "(Ljava/lang/String;)I", MediaStore_Images_Media_BUCKET_DISPLAY_NAME.object<jstring>());
qDebug() << "bucketColumn = " << bucketColumn;
/*
int dateColumn = cur.getColumnIndex(
MediaStore.Images.Media.DATE_TAKEN);
*/
jint dateColumn = cur.callMethod<jint>("getColumnIndex", "(Ljava/lang/String;)I", MediaStore_Images_Media_DATE_TAKEN.object<jstring>());
qDebug() << "dateColumn = " << dateColumn;
jint idColumn = cur.callMethod<jint>("getColumnIndex", "(Ljava/lang/String;)I", MediaStore_Images_Media__ID.object<jstring>());
qDebug() << "idColumn = " << idColumn;
jint bucketIdColumn = cur.callMethod<jint>("getColumnIndex", "(Ljava/lang/String;)I", MediaStore_Images_Media_BUCKET_ID.object<jstring>());
qDebug() << "bucketIdColumn = " << bucketIdColumn;
jint mediaColumnsDataColumn = cur.callMethod<jint>("getColumnIndex", "(Ljava/lang/String;)I", MediaStore_MediaColumns_DATA.object<jstring>());
qDebug() << "mediaColumnsDataColumn = " << mediaColumnsDataColumn;
jint widthColumn = cur.callMethod<jint>("getColumnIndex", "(Ljava/lang/String;)I", MediaStore_MediaColumns_WIDTH.object<jstring>());