Skip to content

Android Substitutions

Peter Lewis edited this page Jul 30, 2021 · 4 revisions

File substitution contents

Files at the app or module directory named as any of the below will substitute its contents into the described areas upon compilation for Android.

ANDROID_c_defines

C #define macros.

ANDROID_c_additions

Additional C code.

ANDROID_java_imports

Java import statements. These will be inserted in the file where the main Activity class is located.

ANDROID_java_implements

Comma-separated list of Java classes that the main Activity class implements. These will be inserted after the implements keyword of the main Activity class.

ANDROID_java_variables

Java variable declarations. Include all keywords and initializations when applicable, and the final semicolon (e.g. private static final int answer = 42;). These will be inserted inside the main Activity class at the top.

ANDROID_java_oncreate

Java code to be executed in the main Activity's override of onCreate. This will be inserted at the end of onCreate, but before the main event loop is called. Its Bundle argument is named savedInstanceState.

By default, the following settings and flags have been set in onCreate before the substitutions:

  • Orientation ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
  • Window feature Window.FEATURE_NO_TITLE;
  • Audio manager setting AudioManager.STREAM_MUSIC; and
  • Window flag WindowManager.LayoutParams.FLAG_FULLSCREEN.

Code to override these settings and flags should therefore be located in ANDROID_java_oncreate. For instance, to enable keeping the screen on, call getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); in this file.

ANDROID_java_onpause

Java code to be executed in the main Activity's override of onPause. This will be inserted before the call to trigger an EVENT_SUSPEND event in Scheme.

ANDROID_java_onresume

Java code to be executed in the main Activity's override of onResume. This will be inserted before the call to trigger an EVENT_RESUME event in Scheme.

ANDROID_java_ondestroy

Java code to be executed in the main Activity's override of onDestroy. This will be inserted before the call to trigger the EVENT_CLOSE and EVENT_TERMINATE events in Scheme.

ANDROID_java_onsensorchanged

Java code to be executed in the main Activity's override of onSensorChanged.

ANDROID_java_activityadditions

Additional Java code that will be inserted in the main Activity class. Some common uses of this file include:

  • Overriding other methods of Activity (that are not onCreate, onDestroy, onStop, onPause, onResume, onAccuracyChanged, or onSensorChanged);
  • Declaring native methods implemented using JNI, commonly located in ANDROID_c_additions; etc.

ANDROID_java_additions

Additional java code that will be inserted outside the main Activity class. Some common uses of this file include:

  • Declaring native methods implemented using JNI, commonly located in ANDROID_c_additions;
  • Implementing additional methods that may be called using JNI from ANDROID_c_additions; etc.

ANDROID_xml_permissions

XML that will be inserted into the app's AndroidManifest.xml file within the <manifest> tag. This file will usually contain <uses-*> tags, especially <uses-permission>; see here for a full list of allowed subtags (excluding <application>).

ANDROID_intent_filters

XML that will be inserted into the app's AndroidManifest.xml file within the <activity> tag. This file should only contain <intent-filter> tags.

ANDROID_xml_receivers

XML that will be inserted into the app's AndroidManifest.xml file within the <application> tag. This file should only contain <receiver> tags.

ANDROID_xml_services

XML that will be inserted into the app's AndroidManifest.xml file within the <application> tag. This file should only contain <service> tags.

ANDROID_activity_attributes

XML that will be inserted into the app's AndroidManifest.xml file as attributes of the <activity> tag. See here for a full list of allowed attributes.

Clone this wiki locally