QAndroidJniEnvironment 提供對 JNI 環境的訪問。 更多...
| 頭: | #include <QAndroidJniEnvironment> |
| qmake: | QT += androidextras |
| Since: | Qt 5.2 |
該類在 Qt 5.2 引入。
| QAndroidJniEnvironment () | |
| ~QAndroidJniEnvironment () | |
| jclass | findClass (const char * className ) |
| JNIEnv * | operator JNIEnv * () const |
| JNIEnv * | operator-> () |
| JavaVM * | javaVM () |
構造新的 QAndroidJniEnvironment 對象並將當前綫程附加到 Java VM。
bool exceptionCheck()
{
/*
The QAndroidJniEnvironment attaches the current thread to the JavaVM on
creation and detach when it goes out of scope.
*/
QAndroidJniEnvironment qjniEnv;
return qjniEnv->ExceptionCheck();
}
分離當前綫程從 Java VM 和銷毀 QAndroidJniEnvironment 對象。
搜索 className using all available class loaders. Qt on Android uses a custom class loader to load all the .jar files and it must be used to find any classes that are created by that class loader because these classes are not visible in the default class loader.
返迴類指針或 null 若沒有找到。
A use case for this function is searching for a custom class then calling its memeber method. The following code snippet create an instance of the class
CustomClass
and then calls
printFromJava()
方法:
QAndroidJniEnvironment env; jclass javaClass = env.findClass("org/qtproject/example/qtandroidextras/CustomClass"); QAndroidJniObject classObject(javaClass); QAndroidJniObject javaMessage = QAndroidJniObject::fromString("findClass example"); classObject.callMethod<void>("printFromJava", "(Ljava/lang/String;)V", javaMessage.object<jstring>());
該函數在 Qt 5.12 引入。
[static]
JavaVM
*QAndroidJniEnvironment::
javaVM
()
返迴 Java VM 接口。
返迴 JNI 環境指針。
提供訪問 QAndroidJniEnvironment 的 JNIEnv 指針。