diff --git a/plugin/protocols/platform/android/PluginUtils.cpp b/plugin/protocols/platform/android/PluginUtils.cpp index dd9bf03227..4f6b6ff99e 100644 --- a/plugin/protocols/platform/android/PluginUtils.cpp +++ b/plugin/protocols/platform/android/PluginUtils.cpp @@ -119,10 +119,10 @@ JNIEnv* PluginUtils::getEnv() } std::map s_PluginObjMap; -std::map s_JObjPluginMap; +std::map s_JObjPluginMap; typedef std::map::iterator ObjMapIter; -typedef std::map::iterator JObjPluginMapIter; +typedef std::map::iterator JObjPluginMapIter; PluginJavaData* PluginUtils::getPluginJavaData(PluginProtocol* pKeyObj) { @@ -135,10 +135,10 @@ PluginJavaData* PluginUtils::getPluginJavaData(PluginProtocol* pKeyObj) return ret; } -PluginProtocol* PluginUtils::getPluginPtr(jobject jobj) +PluginProtocol* PluginUtils::getPluginPtr(std::string className) { PluginProtocol* ret = NULL; - JObjPluginMapIter it = s_JObjPluginMap.find(jobj); + JObjPluginMapIter it = s_JObjPluginMap.find(className); if (it != s_JObjPluginMap.end()) { ret = it->second; } @@ -150,7 +150,7 @@ void PluginUtils::setPluginJavaData(PluginProtocol* pKeyObj, PluginJavaData* pDa { erasePluginJavaData(pKeyObj); s_PluginObjMap.insert(std::pair(pKeyObj, pData)); - s_JObjPluginMap.insert(std::pair(pData->jobj, pKeyObj)); + s_JObjPluginMap.insert(std::pair(pData->jclassName, pKeyObj)); } void PluginUtils::erasePluginJavaData(PluginProtocol* pKeyObj) @@ -162,7 +162,7 @@ void PluginUtils::erasePluginJavaData(PluginProtocol* pKeyObj) { jobject jobj = pData->jobj; - JObjPluginMapIter pluginIt = s_JObjPluginMap.find(jobj); + JObjPluginMapIter pluginIt = s_JObjPluginMap.find(pData->jclassName); if (pluginIt != s_JObjPluginMap.end()) { s_JObjPluginMap.erase(pluginIt); diff --git a/plugin/protocols/platform/android/PluginUtils.h b/plugin/protocols/platform/android/PluginUtils.h index 2bb201b44b..37de6cd58a 100644 --- a/plugin/protocols/platform/android/PluginUtils.h +++ b/plugin/protocols/platform/android/PluginUtils.h @@ -46,7 +46,7 @@ public: static void setPluginJavaData(PluginProtocol* pKeyObj, PluginJavaData* pData); static void erasePluginJavaData(PluginProtocol* pKeyObj); - static PluginProtocol* getPluginPtr(jobject jobj); + static PluginProtocol* getPluginPtr(std::string className); template static void callJavaFunctionWithName_oneBaseType(PluginProtocol* thiz, const char* funcName, const char* paramCode, T param) diff --git a/plugin/protocols/platform/android/ProtocolAds.cpp b/plugin/protocols/platform/android/ProtocolAds.cpp index ea5ce59d03..4e4ba6a87d 100644 --- a/plugin/protocols/platform/android/ProtocolAds.cpp +++ b/plugin/protocols/platform/android/ProtocolAds.cpp @@ -37,9 +37,10 @@ THE SOFTWARE. namespace cocos2d { namespace plugin { extern "C" { - JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_InterfaceAds_nativeOnAdsResult(JNIEnv* env, jobject thiz, jobject obj, jint ret, jstring msg) { + JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_InterfaceAds_nativeOnAdsResult(JNIEnv* env, jobject thiz, jstring className, jint ret, jstring msg) { std::string strMsg = PluginJniHelper::jstring2string(msg); - PluginProtocol* pPlugin = PluginUtils::getPluginPtr(obj); + std::string strClassName = PluginJniHelper::jstring2string(className); + PluginProtocol* pPlugin = PluginUtils::getPluginPtr(strClassName); LOGD("nativeOnAdsResult(), Get plugin ptr : %p", pPlugin); if (pPlugin != NULL) { @@ -52,8 +53,9 @@ extern "C" { } } - JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_InterfaceAds_nativeOnPlayerGetPoints(JNIEnv* env, jobject thiz, jobject obj, jint points) { - PluginProtocol* pPlugin = PluginUtils::getPluginPtr(obj); + JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_InterfaceAds_nativeOnPlayerGetPoints(JNIEnv* env, jobject thiz, jstring className, jint points) { + std::string strClassName = PluginJniHelper::jstring2string(className); + PluginProtocol* pPlugin = PluginUtils::getPluginPtr(strClassName); LOGD("nativeOnPlayerGetPoints(), Get plugin ptr : %p", pPlugin); if (pPlugin != NULL) { diff --git a/plugin/protocols/platform/android/ProtocolIAP.cpp b/plugin/protocols/platform/android/ProtocolIAP.cpp index a85ca0435b..86ba7136ef 100644 --- a/plugin/protocols/platform/android/ProtocolIAP.cpp +++ b/plugin/protocols/platform/android/ProtocolIAP.cpp @@ -37,10 +37,11 @@ THE SOFTWARE. namespace cocos2d { namespace plugin { extern "C" { - JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_InterfaceIAP_nativeOnPayResult(JNIEnv* env, jobject thiz, jobject obj, jint ret, jstring msg) + JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_InterfaceIAP_nativeOnPayResult(JNIEnv* env, jobject thiz, jstring className, jint ret, jstring msg) { std::string strMsg = PluginJniHelper::jstring2string(msg); - PluginProtocol* pPlugin = PluginUtils::getPluginPtr(obj); + std::string strClassName = PluginJniHelper::jstring2string(className); + PluginProtocol* pPlugin = PluginUtils::getPluginPtr(strClassName); LOGD("nativeOnPayResult(), Get plugin ptr : %p", pPlugin); if (pPlugin != NULL) { diff --git a/plugin/protocols/platform/android/ProtocolSocial.cpp b/plugin/protocols/platform/android/ProtocolSocial.cpp index 1398008668..c2a225e1a7 100755 --- a/plugin/protocols/platform/android/ProtocolSocial.cpp +++ b/plugin/protocols/platform/android/ProtocolSocial.cpp @@ -37,10 +37,11 @@ THE SOFTWARE. namespace cocos2d { namespace plugin { extern "C" { - JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_InterfaceSocial_nativeOnShareResult(JNIEnv* env, jobject thiz, jobject obj, jint ret, jstring msg) + JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_InterfaceSocial_nativeOnShareResult(JNIEnv* env, jobject thiz, jstring className, jint ret, jstring msg) { std::string strMsg = PluginJniHelper::jstring2string(msg); - PluginProtocol* pPlugin = PluginUtils::getPluginPtr(obj); + std::string strClassName = PluginJniHelper::jstring2string(className); + PluginProtocol* pPlugin = PluginUtils::getPluginPtr(strClassName); LOGD("nativeOnShareResult(), Get plugin ptr : %p", pPlugin); if (pPlugin != NULL) { diff --git a/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceAds.java b/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceAds.java index 8427234475..3842c6311f 100644 --- a/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceAds.java +++ b/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceAds.java @@ -101,11 +101,13 @@ public class InterfaceAds { PluginWrapper.runOnGLThread(new Runnable(){ @Override public void run() { - InterfaceAds.nativeOnAdsResult(curObj, curCode, curMsg); + String name = curObj.getClass().getName(); + name = name.replace('.', '/'); + InterfaceAds.nativeOnAdsResult(name, curCode, curMsg); } }); } - private native static void nativeOnAdsResult(Object obj, int code, String msg); + private native static void nativeOnAdsResult(String className, int code, String msg); public static void onPlayerGetPoints(AdsAdapter adapter, int points) { final int curPoints = points; @@ -113,9 +115,11 @@ public class InterfaceAds { PluginWrapper.runOnGLThread(new Runnable(){ @Override public void run() { - InterfaceAds.nativeOnPlayerGetPoints(curAdapter, curPoints); + String name = curAdapter.getClass().getName(); + name = name.replace('.', '/'); + InterfaceAds.nativeOnPlayerGetPoints(name, curPoints); } }); } - private native static void nativeOnPlayerGetPoints(Object obj, int points); + private native static void nativeOnPlayerGetPoints(String className, int points); } diff --git a/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceIAP.java b/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceIAP.java index d6a9a91475..340abdc74c 100644 --- a/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceIAP.java +++ b/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceIAP.java @@ -45,9 +45,11 @@ public class InterfaceIAP { PluginWrapper.runOnGLThread(new Runnable() { @Override public void run() { - nativeOnPayResult(curObj, curRet, curMsg); + String name = curObj.getClass().getName(); + name = name.replace('.', '/'); + nativeOnPayResult(name, curRet, curMsg); } }); } - private static native void nativeOnPayResult(Object obj, int ret, String msg); + private static native void nativeOnPayResult(String className, int ret, String msg); } diff --git a/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceSocial.java b/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceSocial.java index be6fcde97c..90147ffc6d 100755 --- a/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceSocial.java +++ b/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceSocial.java @@ -45,9 +45,11 @@ public class InterfaceSocial { PluginWrapper.runOnGLThread(new Runnable() { @Override public void run() { - nativeOnShareResult(curAdapter, curRet, curMsg); + String name = curAdapter.getClass().getName(); + name = name.replace('.', '/'); + nativeOnShareResult(name, curRet, curMsg); } }); } - private static native void nativeOnShareResult(Object obj, int ret, String msg); + private static native void nativeOnShareResult(String className, int ret, String msg); }