Writing an application

In this section we will discuss how you can create your own application using ApertusVR in it.

If you have read the previous section you know how to query events and handle them with entity usage, we can discuss how you can set up ApertusVR for your android application with the support of the JNI-plugin.

On Android, we build our applications from Activity classes, and each activity has its own lifecycle. To learn about activity lifecycles, see the Android guide on activity lifecycles. In code it appears as five function we have to override:

protected void onCreate(Bundle savedInstanceState) {
    // ...

protected void onStart() {
    // ...

protected void onResume() {
    // ...

protected void onPause() {
    // ...

protected void onDestroy() {
    // ...

When the activity is launched (and the onCreate(...) function is called) by Android , we have to do three things:

  1. Get an instance from Android choreographer, and store it for later usages.

  2. Start the ApertusVR system and optionally connect to a room.

  3. Initialize the plug-ins for our application (more about it in the Plugins section).

The 1st is done by typing choreographer = Choreographer.getInstance(). Not a big deal. The 2nd needs further explanation, and we will go through the 3rd in the next section.

Start ApertusVR

Before doing anything with ApertusVR, we have to call its C++ start method in the ape::Systemnamespace:

void Start(const char* configFolderPath, bool isBlocking, std::function<void()> userThreadFunction = std::function<void()>());

When we do that, we have to tell ApertusVR where it can find the apeCore.json file (configFolderPath), which contains necessary informations. On Android it is stored in the assets folder of the given application. Therefore, when calling this method through the JNI-interface and the apeSystem wrapper class, we type:

String configFolderPath = /* some path in the assets folder */;

if (!apeSystem.isRunning()) {
    apeSystem.start(configFolderPath, getAssets());

As you see, we have to provide the Android AssetManager (getAssets()) for the start function. This will call the JNI-function startApertusVR(...), which will call the actual ape::System::Start(...)function.

For reading the asset folder from C++, the Android build has a shared library called apeAAssetOpen. The apeCoreConfig module, uses this shared library to open the asset folder. The JNI-method startApertusVR(...) also initializes apeAAssetOpen library.

Connect to room

ApertusVR users on Android-Java can set the room they want to connect pre-runtime in the apeCore.json, or runtime with the help of the apeSceneNetwork wrapper. So basically everything goes like in the C++ case:

/* start ApertusVR */

String roomName = /* existing room name */

Last updated