By integrating GameTurbo Engine, your app will be able to provide elaborative scene, configuration, and network information for the system to dynamically adjust resource allocation and to adjust the game load based on the status information provided by the system. The system will also feedback status information to the game apps, realizing close and in-depth collaboration between both parties, as well as improved gameplay experience even with restricted system resources.

What You Will Create

In this codelab, you will create a demo project, integrate GameTurbo Engine into the project, and complete the overall deployment of the GameTurbo Engine service.

What You Will Learn

Hardware Requirements

Software Requirements

Required Knowledge

Integrating GameTurbo Engine requires the following preparations:

1. Integrate GameTurbo Engine.

Configure the JAR package of GameTurbo Engine by referring to GameTurbo Engine integration preparations.

2. Obtain a capability object.

public class MainActivity extends Activity { private GameManager mGameManager = GameManager.getGameManager(); ... }

3. Register an app.

Register an app in either of the following ways (depending on whether callback is required):

public class MainActivity extends Activity implements View.OnClickListener { ... private GameManager.GameCallBack gameSdkCallBack = new GameManager.GameCallBack() { @Override public void onPhoneInfoUpdated(String info) { } }; private void registerKitWithCallback() { boolean isSuccess = mGameManager.registerGame(getPackageName(), gameSdkCallBack); } private void registerKitWithoutCallback() { boolean isSuccess = mGameManager.registerGame(getPackageName(), null); } }

4. Send messages to the device.

public class MainActivity extends Activity implements View.OnClickListener { ... private void sendData() { String str = getDataString(); if (str != null) { mGameManager.updateGameAppInfo(str); Toast.makeText(this, "sendData:" + str, Toast.LENGTH_LONG).show(); } } private String getDataString() { JSONObject jsonObject = new JSONObject(); try { jsonObject.put("MessageType", 3); jsonObject.put("SceneID", 1); jsonObject.put("Description", "Game Start"); jsonObject.put("ImportantLevel", "2"); jsonObject.put("RecommendFps", 30); jsonObject.put("KeyThread", "net|6001"); } catch (JSONException e) { return null; } return jsonObject.toString(); } }

5. Obtain device information.

public class MainActivity extends Activity implements View.OnClickListener { ... private String getPhoneInfo() { return mGameManager.getPhoneInfo(); } }

6. Call APIs asynchronously.

It is recommended tht you call APIs of GameTurbo Engine in non-UI threads.

public class MainActivity extends Activity implements View.OnClickListener { ... private static final int MSG_REGISTER_WITH_CALLBACK = 0; private static final int MSG_REGISTER_WITHOUT_CALLBACK = 1; private static final int MSG_SEND_DATA = 2; private static final int MSG_GET_PHONE_INFO = 3; private HandlerThread mWorkThread; private Handler mHandler; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_demo_main); initThread(); ... } private void initThread() { mWorkThread = new HandlerThread("WorkThread"); mWorkThread.start(); mHandler = new Handler(mWorkThread.getLooper(), new Handler.Callback() { @Override public boolean handleMessage(Message message) { switch (message.what) { case MSG_REGISTER_WITH_CALLBACK: registerKitWithCallback(); break; case MSG_REGISTER_WITHOUT_CALLBACK: registerKitWithoutCallback(); break; case MSG_SEND_DATA: sendData(); break; case MSG_GET_PHONE_INFO: getPhoneInfo(); break; default: break; } return false; } }); } ... @Override protected void onDestroy() { super.onDestroy(); mWorkThread.quit(); } }

You have successfully completed this codelab and learned how to:

For more information, please click the following link:
Related Documents


Code copied