Last active
August 29, 2015 14:04
-
-
Save zii/11549933d419bc01d37d to your computer and use it in GitHub Desktop.
lua调用移动SDK的代码
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.cocos2dx.lua; | |
import org.cocos2dx.lib.Cocos2dxLuaJavaBridge; | |
import org.cocos2dx.lib.Cocos2dxActivity; | |
import cn.cmgame.billing.api.BillingResult; | |
import cn.cmgame.billing.api.GameInterface; | |
import cn.cmgame.billing.api.LoginResult; | |
import cn.cmgame.gamepad.api.Gamepad; | |
import cn.cmgame.gamepad.api.KeyState; | |
import cn.cmgame.leaderboard.api.GameLeaderboard; | |
public class Cmbilling | |
{ | |
static Cocos2dxActivity _context = null; | |
// call this in AppActivity.onCreate(), before super.onCreate | |
public static void init(Cocos2dxActivity activity) { | |
_context = activity; | |
GameInterface.initializeApp(activity); | |
} | |
/* | |
* 在lua中调用支付的方法: | |
* local platform = cc.Application:getInstance():getTargetPlatform() | |
* if cc.PLATFORM_OS_ANDROID == platform then | |
* local luaj = require "luaj" | |
* local function callback(result) | |
* print(result) | |
* end | |
* luaj.callStaticMethod("org/cocos2dx/lua/Cmbilling", "dobilling", {true, "001", callback}, "(ZLjava/lang/String;I)V") | |
* end | |
* */ | |
public static void dobilling(final boolean isRepeat, final String index, final int callback) { | |
_context.runOnUiThread(new Runnable() { | |
@Override | |
public void run() { | |
GameInterface.doBilling(_context, true, isRepeat, index, null, new GameInterface.IPayCallback() { | |
@Override | |
public void onResult(final int resultCode, String billingIndex, Object obj) { | |
_context.runOnGLThread(new Runnable() { | |
@Override | |
public void run() { | |
Cocos2dxLuaJavaBridge.callLuaFunctionWithString(callback, ""+resultCode); | |
Cocos2dxLuaJavaBridge.releaseLuaFunction(callback); | |
} | |
}); | |
} | |
}); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment