我正在使用 Necessitas(Android 中的 QT)。基本上,使用 Android NDK,android Activity 调用 QT 应用程序 (.so)。
我正在为 GPS 开发一些绑定(bind)。我想我到了那里,但是当我调用方法 requestLocationUpdates(String, Long, Float, LocationListener) 时,我收到了 JNI 警告(JNI 警告预期返回类型“L”)。
部分代码如下:
midGetSystemService = currEnv->GetMethodID(actClass,"getSystemService","(Ljava/lang/String;)Ljava/lang/Object;");
jSystemServiceObj = currEnv->CallObjectMethod(currAct,midGetSystemService,StringArg);
midRequestLocationUpdates = currEnv->GetMethodID(locManClass,"requestLocationUpdates","(Ljava/lang/String;JFLandroid/location/LocationListener;)V");
midConstListener = currEnv->GetMethodID(listenerClass, "<init>", "()V");
jListenerObj = currEnv->NewObject(listenerClass, midConstListener);
currEnv->CallObjectMethod(jSystemServiceObj,midRequestLocationUpdates,StringArg,(jlong)1000,(jfloat)10,jListenerObj); --->Here is the warning
知道为什么吗?
最佳答案
您正在调用一个返回“void”的方法:
midConstListener = currEnv->GetMethodID(listenerClass, "<init>", "()V");
使用期望返回 JNI 对象的 JNI 调用:
// BAD
currEnv->CallObjectMethod(jSystemServiceObj,midRequestLocationUpdates,StringArg,(jlong)1000,(jfloat)10,jListenerObj);
您应该改用期望返回 void 的 JNI 调用:
// GOOD
currEnv->CallVoidMethod(jSystemServiceObj,midRequestLocationUpdates,StringArg,(jlong)1000,(jfloat)10,jListenerObj);
关于android - JNI 警告预期返回类型 'L' 调用 LocationManager.requestLocationUpdates,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6017646/