- Home /
Integrating AdWhirl for Android with Unity
Hello.
We'd like to use AdWhirl on our Unity Android app. However, this is turning out difficult as there's no Prime31 plugin for this combination. As far as I understand, I need to add it in Eclipse, following these instructions: https://www.adwhirl.com/doc/android/AdWhirlAndroidSDKSetup.html
I've managed to create an Eclipse project and add the AdWhirl and AdMob .jar files into my build path (steps 1 and 2). However, as a newbie to Android programming (though not Java), I'm not sure how to integrate the code given in step 4 into the code Unity generated. Should I just add it in the end of the onCreate method? I'm particularly confused by the various views. I'm guessing I shouldn't, at least, duplicate the setContentView call... Here's the code given for the AdWhirl app:
public class HelloAdWhirl extends Activity implements AdWhirlInterface {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
AdWhirlManager.setConfigExpireTimeout(1000 * 60 * 5);
AdWhirlTargeting.setAge(23);
AdWhirlTargeting.setGender(AdWhirlTargeting.Gender.MALE);
AdWhirlTargeting.setKeywords("online games gaming");
AdWhirlTargeting.setPostalCode("94123");
AdWhirlTargeting.setTestMode(false);
AdWhirlLayout adWhirlLayout = (AdWhirlLayout)findViewById(R.id.adwhirl_layout);
TextView textView = new TextView(this);
RelativeLayout.LayoutParams layoutParams = new
RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
int diWidth = 320;
int diHeight = 52;
int density = getResources().getDisplayMetrics().density;
adWhirlLayout.setAdWhirlInterface(this);
adWhirlLayout.setMaxWidth((int)(diWidth * density));
adWhirlLayout.setMaxHeight((int)(diHeight * density));
layoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
textView.setText("Below AdWhirlLayout");
LinearLayout layout = (LinearLayout)findViewById(R.id.layout_main);
layout.setGravity(Gravity.CENTER_HORIZONTAL);
layout.addView(adWhirlLayout, layoutParams);
layout.addView(textView, layoutParams);
layout.invalidate();
}
}
And here's the code of the Unity generated activity file that I'm guessing is the one I should add the AdWhirl stuff into:
package com.horttanagamedev.eurovision;
import com.unity3d.player.*;
import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
public class TestProjectActivity extends Activity
{
private UnityPlayer mUnityPlayer;
// UnityPlayer.init() should be called before attaching the view to a layout.
// UnityPlayer.quit() should be the last thing called; it will terminate the process and not return.
protected void onCreate (Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setTheme(android.R.style.Theme_NoTitleBar_Fullscreen);
requestWindowFeature(Window.FEATURE_NO_TITLE);
mUnityPlayer = new UnityPlayer(this);
if (mUnityPlayer.getSettings ().getBoolean ("hide_status_bar", true))
getWindow ().setFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
int glesMode = mUnityPlayer.getSettings().getInt("gles_mode", 1);
boolean trueColor8888 = false;
mUnityPlayer.init(glesMode, trueColor8888);
View playerView = mUnityPlayer.getView();
setContentView(playerView);
playerView.requestFocus();
}
protected void onDestroy ()
{
super.onDestroy();
mUnityPlayer.quit();
}
// onPause()/onResume() must be sent to UnityPlayer to enable pause and resource recreation on resume.
protected void onPause()
{
super.onPause();
mUnityPlayer.pause();
if (isFinishing())
mUnityPlayer.quit();
}
protected void onResume()
{
super.onResume();
mUnityPlayer.resume();
}
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
mUnityPlayer.configurationChanged(newConfig);
}
public void onWindowFocusChanged(boolean hasFocus)
{
super.onWindowFocusChanged(hasFocus);
mUnityPlayer.windowFocusChanged(hasFocus);
}
// Pass any keys not handled by (unfocused) views straight to UnityPlayer
public boolean onKeyDown(int keyCode, KeyEvent event)
{
return mUnityPlayer.onKeyDown(keyCode, event);
}
public boolean onKeyUp(int keyCode, KeyEvent event)
{
return mUnityPlayer.onKeyUp(keyCode, event);
}
}
Your answer
Follow this Question
Related Questions
Android game displays 2 game icons 0 Answers
how to integrate unity3d in eclipse IDE? 1 Answer
Admob works on an empty project but not on my actual project 0 Answers
Android Java Proxy could not be found. 0 Answers
StartApp integration 1 Answer