本文整理汇总了C++中QAndroidJniEnvironment::FindClass方法的典型用法代码示例。如果您正苦于以下问题:C++ QAndroidJniEnvironment::FindClass方法的具体用法?C++ QAndroidJniEnvironment::FindClass怎么用?C++ QAndroidJniEnvironment::FindClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QAndroidJniEnvironment
的用法示例。
在下文中一共展示了QAndroidJniEnvironment::FindClass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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
}
示例2: createHashMap
static jobject createHashMap(const QVariantMap &data) {
QAndroidJniEnvironment env;
jclass mapClass = env->FindClass("java/util/HashMap");
if (mapClass == NULL) {
qWarning() << "Failed to find class" << "java/util/HashMap";
return NULL;
}
jclass integerClass = env->FindClass("java/lang/Integer");
jmethodID integerConstructor = env->GetMethodID(integerClass, "<init>", "(I)V");
jclass booleanClass = env->FindClass("java/lang/Boolean");
jmethodID booleanConstructor = env->GetMethodID(booleanClass,"<init>","(Z)V");
jsize map_len = data.size();
jmethodID init = env->GetMethodID(mapClass, "<init>", "(I)V");
jobject hashMap = env->NewObject( mapClass, init, map_len);
jmethodID put = env->GetMethodID( mapClass, "put",
"(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
QMapIterator<QString, QVariant> iter(data);
while (iter.hasNext()) {
iter.next();
// qDebug() << iter.key() << iter.value();
QString key = iter.key();
jstring jkey = env->NewStringUTF(key.toLocal8Bit().data());
QVariant v = iter.value();
if (v.type() == QVariant::String) {
QString str = v.toString();
jstring vString = env->NewStringUTF(str.toLocal8Bit().data());
env->CallObjectMethod(hashMap,put,jkey,vString);
} else if (v.type() == QVariant::Int) {
jobject integer = env->NewObject(integerClass,integerConstructor,v.toInt());
env->CallObjectMethod(hashMap,put,jkey,integer);
} else if (v.type() == QVariant::Bool) {
jobject boolean = env->NewObject(booleanClass,booleanConstructor,v.toBool());
env->CallObjectMethod(hashMap,put,jkey,boolean);
} else {
qWarning() << "QASystemDispatcher: Non-supported data type - " << v.type();
}
}
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
env->ExceptionClear();
}
return hashMap;
}
示例3: callStaticBooleanMethod
void tst_QAndroidJniObject::callStaticBooleanMethod()
{
QAndroidJniEnvironment env;
jclass cls = env->FindClass("java/lang/Boolean");
QVERIFY(cls != 0);
{
QAndroidJniObject parameter = QAndroidJniObject::fromString("true");
QVERIFY(parameter.isValid());
jboolean b = QAndroidJniObject::callStaticMethod<jboolean>(cls,
"parseBoolean",
"(Ljava/lang/String;)Z",
parameter.object<jstring>());
QVERIFY(b);
}
{
QAndroidJniObject parameter = QAndroidJniObject::fromString("false");
QVERIFY(parameter.isValid());
jboolean b = QAndroidJniObject::callStaticMethod<jboolean>(cls,
"parseBoolean",
"(Ljava/lang/String;)Z",
parameter.object<jstring>());
QVERIFY(!b);
}
}
示例4: registerNatives
void QASystemDispatcher::registerNatives()
{
#ifdef Q_OS_ANDROID
QAndroidJniEnvironment env;
jclass clazz = env->FindClass(JCLASS_Name);
if (!clazz)
{
qCritical() << QString("Can't find %1 class").arg(QString(JCLASS_Name));
return ;
}
JNINativeMethod methods[] =
{
{"jniEmit", EMIT_SIGNATURE, (void *)&jniEmit},
};
int numMethods = sizeof(methods) / sizeof(methods[0]);
if (env->RegisterNatives(clazz, methods, numMethods) < 0) {
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
env->ExceptionClear();
qCritical() << "Exception occurred!!!";
return;
}
}
#endif
}
示例5: getStaticIntField
void tst_QAndroidJniObject::getStaticIntField()
{
QAndroidJniEnvironment env;
jclass cls = env->FindClass("java/lang/Double");
QVERIFY(cls != 0);
jint i = QAndroidJniObject::getStaticField<jint>(cls, "SIZE");
QCOMPARE(i, 64);
}
示例6: getStaticByteField
void tst_QAndroidJniObject::getStaticByteField()
{
QAndroidJniEnvironment env;
jclass cls = env->FindClass("java/lang/Byte");
QVERIFY(cls != 0);
jbyte i = QAndroidJniObject::getStaticField<jbyte>(cls, "MAX_VALUE");
QCOMPARE(i, jbyte(127));
}
示例7: getStaticLongField
void tst_QAndroidJniObject::getStaticLongField()
{
QAndroidJniEnvironment env;
jclass cls = env->FindClass("java/lang/Long");
QVERIFY(cls != 0);
jlong i = QAndroidJniObject::getStaticField<jlong>(cls, "MAX_VALUE");
QCOMPARE(i, jlong(9223372036854775807L));
}
示例8: getStaticShortField
void tst_QAndroidJniObject::getStaticShortField()
{
QAndroidJniEnvironment env;
jclass cls = env->FindClass("java/lang/Short");
QVERIFY(cls != 0);
jshort i = QAndroidJniObject::getStaticField<jshort>(cls, "MAX_VALUE");
QCOMPARE(i, jshort(32767));
}
示例9: getStaticCharField
void tst_QAndroidJniObject::getStaticCharField()
{
QAndroidJniEnvironment env;
jclass cls = env->FindClass("java/lang/Character");
QVERIFY(cls != 0);
jchar i = QAndroidJniObject::getStaticField<jchar>(cls, "MAX_VALUE");
QCOMPARE(i, jchar(0xffff));
}
示例10: getStaticDoubleField
void tst_QAndroidJniObject::getStaticDoubleField()
{
QAndroidJniEnvironment env;
jclass cls = env->FindClass("java/lang/Double");
QVERIFY(cls != 0);
jdouble i = QAndroidJniObject::getStaticField<jdouble>(cls, "NaN");
jlong *k = reinterpret_cast<jlong*>(&i);
QCOMPARE(*k, jlong(0x7ff8000000000000L));
}
示例11: getStaticFloatField
void tst_QAndroidJniObject::getStaticFloatField()
{
QAndroidJniEnvironment env;
jclass cls = env->FindClass("java/lang/Float");
QVERIFY(cls != 0);
jfloat i = QAndroidJniObject::getStaticField<jfloat>(cls, "NaN");
unsigned *k = reinterpret_cast<unsigned*>(&i);
QCOMPARE(*k, unsigned(0x7fc00000));
}
示例12: callStaticCharMethod
void tst_QAndroidJniObject::callStaticCharMethod()
{
QAndroidJniEnvironment env;
jclass cls = env->FindClass("java/lang/Character");
QVERIFY(cls != 0);
jchar returnValue = QAndroidJniObject::callStaticMethod<jchar>(cls,
"toUpperCase",
"(C)C",
jchar('a'));
QCOMPARE(returnValue, jchar('A'));
}
示例13: ctor
void tst_QAndroidJniObject::ctor()
{
{
QAndroidJniObject object;
QVERIFY(!object.isValid());
}
{
QAndroidJniObject object("java/lang/String");
QVERIFY(object.isValid());
}
{
QAndroidJniObject string = QAndroidJniObject::fromString(QLatin1String("Hello, Java"));
QAndroidJniObject object("java/lang/String", "(Ljava/lang/String;)V", string.object<jstring>());
QVERIFY(object.isValid());
QCOMPARE(string.toString(), object.toString());
}
{
QAndroidJniEnvironment env;
jclass javaStringClass = env->FindClass("java/lang/String");
QAndroidJniObject string(javaStringClass);
QVERIFY(string.isValid());
}
{
QAndroidJniEnvironment env;
const QString qString = QLatin1String("Hello, Java");
jclass javaStringClass = env->FindClass("java/lang/String");
QAndroidJniObject string = QAndroidJniObject::fromString(qString);
QAndroidJniObject stringCpy(javaStringClass, "(Ljava/lang/String;)V", string.object<jstring>());
QVERIFY(stringCpy.isValid());
QCOMPARE(qString, stringCpy.toString());
}
}
示例14: callStaticByteMethod
void tst_QAndroidJniObject::callStaticByteMethod()
{
QAndroidJniEnvironment env;
jclass cls = env->FindClass("java/lang/Byte");
QVERIFY(cls != 0);
QString number = QString::number(123);
QAndroidJniObject parameter = QAndroidJniObject::fromString(number);
jbyte returnValue = QAndroidJniObject::callStaticMethod<jbyte>(cls,
"parseByte",
"(Ljava/lang/String;)B",
parameter.object<jstring>());
QCOMPARE(returnValue, jbyte(number.toInt()));
}
示例15: callStaticLongMethod
void tst_QAndroidJniObject::callStaticLongMethod()
{
QAndroidJniEnvironment env;
jclass cls = env->FindClass("java/lang/Long");
QVERIFY(cls != 0);
QString number = QString::number(123);
QAndroidJniObject parameter = QAndroidJniObject::fromString(number);
jlong returnValue = QAndroidJniObject::callStaticMethod<jlong>(cls,
"parseLong",
"(Ljava/lang/String;)J",
parameter.object<jstring>());
QCOMPARE(returnValue, jlong(number.toLong()));
}