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 }
bool JniNative::registerNativeMethods() { JNINativeMethod methods[] { {"notifyMsg", "(III)V", (void*)notifyMsg}, {"setDirectBuffer","(Ljava/lang/Object;I)V",(void*)setDirectBuffer} }; const char *classname = "an/qt/useJar/ExtendsQtNative"; jclass clazz; QAndroidJniEnvironment env; QAndroidJniObject javaClass(classname); clazz = env->GetObjectClass(javaClass.object<jobject>()); // QDBG << "find ExtendsQtNative - " << clazz; bool result = false; if (clazz) { jint ret = env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); env->DeleteLocalRef(clazz); // QDBG << "RegisterNatives return - " << ret; result = ret >= 0; } if (env->ExceptionCheck()) env->ExceptionClear(); return result; }
static bool registerNativeMethods() { JNINativeMethod methods[] { {"OnImageCaptured", "(ILjava/lang/String;)V", (void*)onImageCaptured} }; const char *classname = "an/qt/imageProcessor/ImageCaptureNative"; jclass clazz; QAndroidJniEnvironment env; QAndroidJniObject javaClass(classname); clazz = env->GetObjectClass(javaClass.object<jobject>()); //clazz = env->FindClass(classname); qDebug() << "find ImageCaptureNative - " << clazz; bool result = false; if(clazz) { jint ret = env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); env->DeleteLocalRef(clazz); qDebug() << "RegisterNatives return - " << ret; result = ret >= 0; } if(env->ExceptionCheck()) env->ExceptionClear(); return result; }
void QQmlAndroidScrollView::onRegisterNativeMethods(jobject listener) { JNINativeMethod methods[] {{"onScrollChanged", "(JII)V", reinterpret_cast<void *>(onScrollChanged)}}; QAndroidJniEnvironment env; jclass cls = env->GetObjectClass(listener); env->RegisterNatives(cls, methods, sizeof(methods) / sizeof(methods[0])); env->DeleteLocalRef(cls); }
bool aseman_android_loclis_registerNativeMethods() { JNINativeMethod methods[] {{"_locationListened", "(DDDLjava/lang/String;)V", reinterpret_cast<void *>(locationListened)}}; QAndroidJniObject javaClass("land/aseman/android/extra/AsemanLocationListener"); QAndroidJniEnvironment env; jclass objectClass = env->GetObjectClass(javaClass.object<jobject>()); env->RegisterNatives(objectClass, methods, sizeof(methods) / sizeof(methods[0])); env->DeleteLocalRef(objectClass); return true; }
void AndroidScreenDevPrivate::registerNatives() { static bool ready = false; if (ready) return; QAndroidJniEnvironment jenv; if (auto jclass = jenv.findClass(JCLASS(AkAndroidScreenCallbacks))) { QVector<JNINativeMethod> methods { {"imageAvailable", "(JIIIJ[B)V", reinterpret_cast<void *>(AndroidScreenDevPrivate::imageAvailable)}, {"captureStopped", "(J)V" , reinterpret_cast<void *>(AndroidScreenDevPrivate::captureStopped)}, }; jenv->RegisterNatives(jclass, methods.data(), methods.size()); } ready = true; }
void QSerialPortPrivate::setNativeMethods(void) { qCDebug(AndroidSerialPortLog) << "Registering Native Functions"; // REGISTER THE C++ FUNCTION WITH JNI JNINativeMethod javaMethods[] { {"nativeDeviceHasDisconnected", "(I)V", reinterpret_cast<void *>(jniDeviceHasDisconnected)}, {"nativeDeviceNewData", "(I[B)V", reinterpret_cast<void *>(jniDeviceNewData)}, {"nativeDeviceException", "(ILjava/lang/String;)V", reinterpret_cast<void *>(jniDeviceException)}, {"qgcLogDebug", "(Ljava/lang/String;)V", reinterpret_cast<void *>(jniLogDebug)}, {"qgcLogWarning", "(Ljava/lang/String;)V", reinterpret_cast<void *>(jniLogWarning)} }; QAndroidJniEnvironment jniEnv; if (jniEnv->ExceptionCheck()) { jniEnv->ExceptionDescribe(); jniEnv->ExceptionClear(); } jclass objectClass = jniEnv->FindClass(kJniClassName); if(!objectClass) { qWarning() << "Couldn't find class:" << kJniClassName; return; } jint val = jniEnv->RegisterNatives(objectClass, javaMethods, sizeof(javaMethods) / sizeof(javaMethods[0])); if (val < 0) { qWarning() << "Error registering methods: " << val; } else { qCDebug(AndroidSerialPortLog) << "Native Functions Registered"; } if (jniEnv->ExceptionCheck()) { jniEnv->ExceptionDescribe(); jniEnv->ExceptionClear(); } }