Anyone programming using Necessitas (Qt for Android)?
I am working with Necessitas (Qt for Android). All run fine.
Now, I am trying to connect to the Dalvik JVM to use some of the Android API (GPS for example). To do this I'm trying to g开发者_如何学运维et the Java environment using JNI:
JNIEnv *currEnv;
currEnv = 0;
if (m_javaVM->GetEnv((void**)&currEnv,JNI_VERSION_1_4) == JNI_OK)
{
qDebug() << "GetEnv passed";
}
else
{
qDebug() << "GetEnv failed";
}
m_javaVM
is the pointer to the virtual machine used by Necessitas.
The problem is that I always get GetEnv failed when I run the application in the android virtual device.
Any help is much appreciated!
I am answering my ow question:
This happens because getEnv gets the current env. While what i need to to get a new env with something like:
if (currVM->AttachCurrentThread((void **)&currEnv, NULL)<0)
{
emit error("Cannot attach the current thread to the VM");
}
精彩评论