My way to add Ads is by code. Maybe the only way coz basic in graphics
does not load any layout. All is done by code.
If you want to add ads first checkout "Android finishing touches" parts 1-4 on youtube
Don't give any importance to the commands added.
Just setup correctly admob, and integrate it correctly into your project.
The size of the apk should increase by about 78k.
Add in the manifest the required permissions.
When you are ready with this, let me know.
I will tell you the further steps to make it work.
Remember that you must have 50x320 pixels of empty space in your app, in all resolutions, starting out from the 240x320 resolution.
I've placed that code in gr.java
so ads start when program goes into the graphics screen.
It doesn't use any xml files, just code.
My code is based on something like this:
When you are testing remember to use
Code:
adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
and test over the emulator.
If you press on ads on your device your admob account will be closed forever!
// in gr.java
import com.google.ads.AdRequest;
import com.google.ads.AdSize;
import com.google.ads.AdView;
//find these lines and replace
@Override
public void onCreate(Bundle savedInstanceState) {
Log.v(GR.LOGTAG, " " + GR.CLASSTAG + " On Create ");
super.onCreate(savedInstanceState);
setVolumeControlStream(AudioManager.STREAM_MUSIC);
if (Run.ShowStatusBar != 0){
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN, WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
}else{
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
requestWindowFeature(Window.FEATURE_NO_TITLE);
int Mode = Run.GRorientation;
if (Mode == -1) setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
else if (Mode == 0) setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
else setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
drawView = new DrawView(this);
// setContentView(drawView);
drawView.requestFocus();
drawView.setBackgroundColor(theBackGround);
drawView.setId(33);
Display display = getWindowManager().getDefaultDisplay();
Width = display.getWidth();
Heigth = display.getHeight();
scaleX = 1.0f;
scaleY = 1.0f;
Brightness = -1;
Rendering = false;
// admob code
AdView admobView = new AdView(this, AdSize.BANNER, "YourAdmobId");
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
admobView.setLayoutParams(lp);
RelativeLayout layout = new RelativeLayout(this);
layout.addView(drawView);
layout.addView(admobView);
AdRequest adRequest = new AdRequest();
admobView.loadAd(adRequest);
adRequest.addTestDevice(AdRequest.TEST_EMULATOR); // remove this after testing
setContentView(layout);
// finished
// in manifest
_________________