Android Services

1. Introduction

Android Services

When you use our build tool to package your game for Android, you can easily add services to the project. They allow to comfortably access various Android services (from Google and other 3rd parties, like ad networks) from your Object Pascal game code using the Castle Game Engine.

The Android services are declared in CastleEngineManifest.xml like this:

<android>
  <services>
    <service name="google_play_services" />
    <service name="google_in_app_purchases" />
  </services>
</android>

3. Note on Android project types

Using the <android> element, you can request a project type:

  • <android project_type="base">: No extra integration, the final project does not use any Java code at all. Rendering and inputs work 100%, since they don’t require anything extra. This may be enough for some games. However no services can work.

  • <android project_type="integrated">: (This is the default in CGE >= 6.5.) We include extra Java integration code that allows to use Android project services that communicate with Object Pascal code. This opens the door for the services mentioned below. It also allows to integrate with various native-code libraries (like FreeType and OpenAL).

Merely declaring the project type as "integrated" (even without any extra services) immediately gives you:

  • Immersive mode on newer Android devices. This is a "true" full-screen mode for games on Android, where the back/home buttons are usually hidden.

  • You can open URLs in external applications using OpenURL from CastleOpenDocument unit. Hint: use special market:// URL to send users to the Google Play store, e.g. to rate your application.

  • You can share text and links with other applications. Use ShareText from the CastleOpenDocument unit.

  • You can send Android standard on-screen notification ("toast") using OnScreenNotification from the CastleOpenDocument unit.

  • Some services (like sound and ogg_vorbis) will be added automatically to your project if the sound files are detected in your game data. So merely declaring your project type as "integrated" makes sound work on Android.

4. Adding new services


To improve this documentation just edit the source of this page in AsciiDoctor (simple wiki-like syntax) and create a pull request to Castle Game Engine WWW (cge-www) repository.