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; }
bool PathManager::ReplacePakNameInXml(QString &srcPath, QString &fileName, QString &oldName, QString &newName) { if (fileName.toLower().endsWith(".xml")){ QFile file(fileName); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)){ return false; } QTextStream in(&file); in.setCodec("UTF-8"); QString content; content = in.readAll(); file.close(); QString contentEx = QString("<[^<>]*%1[^<>]*>").arg(oldName); for (int i = 0; i < content.length();) { i = content.indexOf(QRegExp(contentEx), i); if (i < 0){ break; } i = content.indexOf(oldName, i); if (i < 0){ break; } int offset = i + oldName.length(); if (offset >= content.length()){ break; } QString remain = content.mid(i + oldName.length() + 1); int newOffset = remain.indexOf(QRegExp("\\.|\""), 0); if (newOffset < 0){ break; } QString packName = oldName; QString className = remain.left(newOffset); QFile javaClass(srcPath + "/src/" + packName.replace(".", "/") + "/" + className + ".java"); if (javaClass.exists()){ content.remove(i, oldName.length()); content.insert(i, newName); } i = offset; } if (!QFile::remove(fileName)){ return false; } QFile newfile(fileName); if (!newfile.open(QIODevice::ReadWrite | QIODevice::Text)){ return false; } newfile.write(content.toUtf8()); newfile.close(); return true; } return true; }
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; }
bool PathManager::ReplacePakNameInJava(QString &srcPath, QString &fileName, QString &oldName, QString &newName) { if (fileName.toLower().endsWith(".java")){ QString regularEx = QString("(?<=(\\bpackage)|(\\bimport))[\\s\\t\\r\\n]+%1[\\s\\t\\r\\n]*;").arg(oldName); QString replaceName = QString(" ") + newName + ";"; QFile file(fileName); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)){ return false; } QTextStream in(&file); in.setCodec("UTF-8"); QString content; content = in.readAll(); file.close(); ReplaceByRegular(regularEx, content, replaceName); QString contentEx = QString("(?<=[({};])[\\s\\t\\r\\n]*%1\\.").arg(oldName); SPCRE *spcre = PCRECache::instance()->getObject(contentEx); QList<SPCRE::MatchInfo> match_info = spcre->getEveryMatchInfo(content); for (int i = match_info.count() - 1; i >= 0; i--) { QString replaced_text; bool replacement_made = spcre->replaceText(content.mid(match_info.at(i).offset.first, match_info.at(i).offset.second - match_info.at(i).offset.first), match_info.at(i).capture_groups_offsets, newName + ".", replaced_text); if (replacement_made) { int pos = content.indexOf(QRegExp("\\.|\\s"), match_info.at(i).offset.second); // Replace the text. if (pos < 0){ continue; } QString classNm = content.mid(match_info.at(i).offset.second, pos - match_info.at(i).offset.second); QString packName = oldName; QFile javaClass(srcPath + "/src/" + packName.replace(".", "/") + "/" + classNm + ".java"); if (javaClass.exists()){ content = content.replace(match_info.at(i).offset.first, match_info.at(i).offset.second - match_info.at(i).offset.first, replaced_text); } } } if (!QFile::remove(fileName)){ return false; } QFile newfile(fileName); if (!newfile.open(QIODevice::ReadWrite | QIODevice::Text)){ return false; } newfile.write(content.toUtf8()); newfile.close(); return true; } return true; }
bool AndroidPlatform::getAndroidAsset(JNIEnv* JNIEnvironment, const char destinationDirectory[], const char filename[]) { if (JNIEnvironment == NULL || destinationDirectory == NULL || filename == NULL) { LOGE("getAndroidAsset(): NULL argument is not acceptable.\n"); return false; } /* Create the full path to where we want the file to be found. */ string resourceFilePath = string(destinationDirectory) + string(filename); /* Try and find the file in the file system. */ FILE * file = NULL; file = fopen(resourceFilePath.c_str(), "r"); if (file != NULL) { /* * The file does exist on the target device's file system, * The program can use this file as normal. */ fclose (file); } else { /* The file does not exist and needs to be extracted from the APK package */ /* Use the MaliSamplesActivity.extractAsset() Java method to extract the file */ JavaClass javaClass(JNIEnvironment, "com/arm/malideveloper/openglessdk/MaliSamplesActivity"); /* Extract the file from the asset folder embedded in the APK to the destination directory. */ if (!javaClass.staticMethod("extractAsset", destinationDirectory, filename)) { LOGE("getAndroidAsset(): Failed to call MaliSamplesActivity.extractAsset() for %s\n", filename); return false; } } return true; }