cocos2d中间层调用Android(三)
发布时间:2020-12-14 17:11:15 所属栏目:百科 来源:网络整理
导读:ios通过.cpp文件进行调用AppActivity.java的方法 js_bindings_lcm_api.cpp: //// js_bindings_lcm_api.cpp// MoonWarriors//// Created by xiaohei on 2/21/17.////#include "js_bindings_lcm_api.h"#ifdef ANDROID#include jni/JniHelper.h#endifusing nam
ios通过.cpp文件进行调用AppActivity.java的方法 js_bindings_lcm_api.cpp: // // js_bindings_lcm_api.cpp // MoonWarriors // // Created by xiaohei on 2/21/17. // // #include "js_bindings_lcm_api.h" #ifdef ANDROID #include <jni/JniHelper.h> #endif using namespace LCMJSB; using namespace cocos2d; //LCMAPI* LCMAPI::instance_ = nullptr; LCMAPI* LCMAPI::getInstance() { static LCMAPI instance_; return std::addressof(instance_); } LCMAPI::LCMAPI() { } LCMAPI::~LCMAPI() { } void LCMAPI::continueProcessing() { #ifdef ANDROID JniMethodInfo minfo; bool find = JniHelper::getStaticMethodInfo(minfo,"org/cocos2dx/javascript/AppActivity","continueProcessing","()V"); if (find) { minfo.env->CallStaticObjectMethod(minfo.classID,minfo.methodID); minfo.env->DeleteLocalRef(minfo.classID); } #endif } std::string LCMAPI::getLTotalBalance() { std::string ret = ""; #ifdef ANDROID JniMethodInfo minfo; bool find = JniHelper::getStaticMethodInfo(minfo,"getLTotalBalance","()Ljava/lang/String;"); if (find) { jstring jret = (jstring)minfo.env->CallStaticObjectMethod(minfo.classID,minfo.methodID); ret = JniHelper::jstring2string(jret); minfo.env->DeleteLocalRef(jret); minfo.env->DeleteLocalRef(minfo.classID); } #endif return ret; } bool LCMAPI::getLIsShowBalance() { bool ret = false; #ifdef ANDROID JniMethodInfo minfo; bool find = JniHelper::getStaticMethodInfo(minfo,"getLIsShowBalance","()Z"); if (find) { jboolean jret = (jboolean)minfo.env->CallStaticBooleanMethod(minfo.classID,minfo.methodID); ret = (bool) jret; minfo.env->DeleteLocalRef(minfo.classID); } #endif return ret; } void LCMAPI::lcmNotifyEveryday(int hour,int min,std::string title,std::string txt,std::string icon,int code) { #ifdef ANDROID JniMethodInfo minfo; bool find = JniHelper::getStaticMethodInfo(minfo,"lcmNotifyEveryday","(IILjava/lang/String;Ljava/lang/String;Ljava/lang/String;I)V"); if (find) { jint jhour = (jint)hour; jint jmin = (jint)min; jint jcode = (jint)code; jstring jtitle = minfo.env->NewStringUTF(title.c_str()); jstring jtxt = minfo.env->NewStringUTF(txt.c_str()); jstring jicon = minfo.env->NewStringUTF(icon.c_str()); minfo.env->CallStaticVoidMethod(minfo.classID,minfo.methodID,jhour,jmin,jtitle,jtxt,jicon,jcode); minfo.env->DeleteLocalRef(jtitle); minfo.env->DeleteLocalRef(jtxt); minfo.env->DeleteLocalRef(jicon); minfo.env->DeleteLocalRef(minfo.classID); } #endif }注意传入的参数和返回值的表示,注意转换过程 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |