UmengGame的代码如下, 该代码演示了集成友盟Social SDK的。
/**************************************************************************** Copyright (c) 2010-2011 cocos2d-x.org http://www.cocos2d-x.org Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ package com.umeng.game; import org.cocos2dx.lib.Cocos2dxActivity; import org.cocos2dx.lib.Cocos2dxGLSurfaceView; import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.os.Looper; import android.widget.Toast; import com.umeng.socialize.bean.SHARE_MEDIA; import com.umeng.socialize.bean.SocializeEntity; import com.umeng.socialize.controller.RequestType; import com.umeng.socialize.controller.UMServiceFactory; import com.umeng.socialize.controller.UMSocialService; import com.umeng.socialize.controller.listener.SocializeListeners.SnsPostListener; public class UmengGame extends Cocos2dxActivity { /** * Handler, 用于包装友盟的openShare方法,保证openShare方法在UI线程执行 */ private static Handler mHandler = null; /** * 保存当前Activity实例, 静态变量 */ private static Activity mActivity = null; /** * 友盟Social SDK实例,整个SDK的Controller */ private static UMSocialService mController = UMServiceFactory .getUMSocialService("com.umeng.cocos2dx", RequestType.SOCIAL); /** * */ private static final int DELAY = 100; /* * (non-Javadoc) * * @see org.cocos2dx.lib.Cocos2dxActivity#onCreate(android.os.Bundle) */ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mActivity = this; mHandler = new Handler(Looper.getMainLooper()); mController.setShareContent("COCOS2D-X HACKATHON."); } /** * 打开分享面板 */ public static void openShare() { mHandler.postDelayed(new Runnable() { @Override public void run() { mController.registerListener(mPostListener); // 打开友盟的分享平台选择面板 mController.openShare(mActivity, false); } }, DELAY); } /** * */ public static SnsPostListener mPostListener = new SnsPostListener() { @Override public void onStart() { onNativeStart(); } @Override public void onComplete(SHARE_MEDIA platform, int eCode, SocializeEntity entity) { Toast.makeText(mActivity, platform + ", " + eCode, Toast.LENGTH_SHORT).show(); onNativeComplete(platform.toString(), eCode, entity.mDescriptor); } }; public native static void onNativeStart(); public native static void onNativeComplete(String platform, int eCode, String descriptor); /* * (non-Javadoc) * * @see org.cocos2dx.lib.Cocos2dxActivity#onCreateView() */ public Cocos2dxGLSurfaceView onCreateView() { Cocos2dxGLSurfaceView glSurfaceView = new Cocos2dxGLSurfaceView(this); // UmengGame should create stencil buffer glSurfaceView.setEGLConfigChooser(5, 6, 5, 0, 16, 8); return glSurfaceView; } /** * load lib */ static { System.loadLibrary("cocos2dcpp"); } }