package com.kungfuchef;
import android.app.Activity;
import android.util.*;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import com.google.ads.*;
public class HomeGamerAdViewMaager
{
private Activity context;
private static HomeGamerAdViewMaager instance;
float denesity;
// Point screenSize;
public Activity getContext() {
return context;
}
public void setContext(Activity context) {
this.context = context;
DisplayMetrics displayMetrics = new DisplayMetrics();
displayMetrics = context.getResources().getDisplayMetrics();
//display.getHeight()(screenSize);
denesity = displayMetrics.density;
}
public void showAdview() {
// AdView adView = new AdView(context, AdSize.IAB_MRECT, ((Activity)
// context)
// .getResources().getString(R.string.google_key));
Log.v("aa", "aa");
AdView adView = new AdView(context, AdSize.BANNER, "xxxxx");
//final RelativeLayout parentLayout = new RelativeLayout(context);
// final RelativeLayout.LayoutParams parentLayputParams = new RelativeLayout.LayoutParams(
// (int) (100), (int) (100));
// parentLayputParams.addRule(RelativeLayout.CENTER_IN_PARENT, 1);
//parentLayout.addView(adView, parentLayputParams);
Log.v("abba", "abba");
adView.loadAd(new AdRequest());
//private static View getRootView(Activity context)
//{
//RelativeLayout layOut = new RelativeLayout(context);
//RelativeLayout.LayoutParams adViewLayoutParam = new RelativeLayout.LayoutParams((AdSize.BANNER.getWidth(),
//AdSize.BANNER.getHeight());
//adViewLayoutParam.addRule(RelativeLayout.ALIGN_PARENT_TOP);
//layOut.addView(adView);//, adViewLayoutParam);
//ViewGroup group = (ViewGroup)context.findViewById(android.R.id.content);
//group.addView(adView);
LinearLayout layout = new LinearLayout(context);
layout.setOrientation(LinearLayout.VERTICAL);
context.addContentView(layout, new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
layout.addView(adView, new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
}
public static HomeGamerAdViewMaager GetInstance() {
if (instance == null)
instance = new HomeGamerAdViewMaager();
return instance;
}
}
unityPlayer.java
package com.kungfuchef;
import com.kungfuchef.HomeGamerAdViewManager;
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 UnityPlayerActivity extends Activity
{
private UnityPlayer mUnityPlayer;
// UnityPlayer.init() should be called before attaching the view to a layout - it will load the native code.
// UnityPlayer.quit() should be the last thing called - it will unload the native code.
protected void onCreate (Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
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();
HomeGamerAdViewManager.GetInstance().setContext(this);
HomeGamerAdViewManager.GetInstance().showAdview();
}
protected void onDestroy ()
{
mUnityPlayer.quit();
super.onDestroy();
}
// onPause()/onResume() must be sent to UnityPlayer to enable pause and resource recreation on resume.
protected void onPause()
{
super.onPause();
mUnityPlayer.pause();
}
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 onKeyMultiple(int keyCode, int count, KeyEvent event)
{
return mUnityPlayer.onKeyMultiple(keyCode, count, event);
}
public boolean onKeyDown(int keyCode, KeyEvent event)
{
return mUnityPlayer.onKeyDown(keyCode, event);
}
public boolean onKeyUp(int keyCode, KeyEvent event)
{
return mUnityPlayer.onKeyUp(keyCode, event);
}
}
here is my code
it works well when I start a empty android project with "hello world" label, but not in unity