-
Notifications
You must be signed in to change notification settings - Fork 1
How To Setup Android
Unfortunately when compiling for android you will be required to modify part of your compiled project code. With the new Monkey version 67d+ you could make a permanent target based off of the existing android target, but that is not within the scope of this tutorial. For this document we will explain how to make the modification directly to the existing android target.
The Chartboost module will work on android without these modifications but you will notice odd behaviour related to pressing the back button while an advert is visible and also when your app stops or starts.
Open the file your_monkey_install_path/targets/android/modules/native/androidgame.java in any notepad/texteditor. Near the bottom of the file you will find a class Called: class AndroidGame extends Activity {
Copy the following methods into the class:
// --------------- chartboost modifications ------------
//these modifications need to be copied into your androidgame.java
@Override
protected void onStart() {
// --- need to pass on this event to chartboost ---
super.onStart();
if (ChartboostGlue.instance != null) { ChartboostGlue.instance.cb.onStart(this); }
}
@Override
protected void onStop() {
// --- need to pass on this event to chartboost ---
super.onStop();
if (ChartboostGlue.instance != null) { ChartboostGlue.instance.cb.onStop(this); }
}
@Override
protected void onDestroy() {
// --- need to pass on this event to chartboost ---
super.onDestroy();
if (ChartboostGlue.instance != null) { ChartboostGlue.instance.cb.onDestroy(this); }
}
@Override
public void onBackPressed(){
// --- handle back event pressed on android ---
//we need to handle this as when chartboost is active, if back is pressed, monkey will exit the app
if (ChartboostGlue.instance != null && ChartboostGlue.instance.cb.onBackPressed()) {
//block the back event
return;
} else {
//deprecating this!
_game.KeyEvent( BBGameEvent.KeyDown,27 );
_game.KeyEvent( BBGameEvent.KeyUp,27 );
//new KEY_BACK value...
_game.KeyEvent( BBGameEvent.KeyDown,0x1a0 );
_game.KeyEvent( BBGameEvent.KeyUp,0x1a0 );
}
}
Make sure you follow the Chartboost.com setup tutorial before you test your app, or it might crash even in test mode.
Chartboost should now be fully integrate for all of your android projects. Please see the file misc/androidgame.java in the module folder to see a version of androidgame.java that has the code already added.