Eclipse, Android, AdMob. No xml

I’m new to Android and this is my first app. I have problem with adding ads. Generally I’ve been following this tutorial http://www.kilobolt.com/unit-1-writing-basic-android-apps.html .

Then I tried following this official thing https://developers.google.com/admob/android/eclipse – I’ve modified android manifest file, strings.xml but I do not have activity_main.xml (Because I didn’t check “create Activity” at the beginning…?).

So after a long searching I found this question:
Android AdMob without XML

So I tried this solution and now I have 2 errors:

AdSize cannot be resolved to a variable AndroidGame.java/gametitle/src/com/username/framework/implementation
The constructor AdRequest() is undefined    AndroidGame.java/gametitle/src/com/username/framework/implementation

(I thought that sth may be wrong with the google play libs I’ve downloaded so I tried making a simple app from the official link mentioned above. There was no errors but the app didn’t run – it just stopped at “launching 99%”.)

Here’s the full code for AndroidGame:

    package com.username.framework.implementation;
import android.app.Activity;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;

import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.os.Bundle;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.view.Window;
import android.view.WindowManager;


import android.widget.RelativeLayout;

import com.username.framework.Audio;
import com.username.framework.FileIO;
import com.username.framework.Game;
import com.username.framework.Graphics;
import com.username.framework.Input;
import com.username.framework.Screen;

public abstract class AndroidGame extends Activity implements Game {
    AndroidFastRenderView renderView;
    Graphics graphics;
    Audio audio;
    Input input;
    FileIO fileIO;
    Screen screen;
    WakeLock wakeLock;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        boolean isPortrait = getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
        int frameBufferWidth = isPortrait ? 480: 800;
        int frameBufferHeight = isPortrait ? 800: 480;
        Bitmap frameBuffer = Bitmap.createBitmap(frameBufferWidth,
                frameBufferHeight, Config.RGB_565);

        float scaleX = (float) frameBufferWidth
                / getWindowManager().getDefaultDisplay().getWidth();
        float scaleY = (float) frameBufferHeight
                / getWindowManager().getDefaultDisplay().getHeight();

        renderView = new AndroidFastRenderView(this, frameBuffer);
        graphics = new AndroidGraphics(getAssets(), frameBuffer);
        fileIO = new AndroidFileIO(this);
        audio = new AndroidAudio(this);
        input = new AndroidInput(this, renderView, scaleX, scaleY);
        screen = getInitScreen();
        //setContentView(renderView);

        RelativeLayout layout = new RelativeLayout(this);
        AdView adView = new AdView(this, AdSize.BANNER, "a151bf25136cf46");
        layout.addView(renderView);
        layout.addView(adView);
        setContentView(layout);
        adView.loadAd(new AdRequest());


        PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
        wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "MyGame");

    }

    @Override
    public void onResume() {
        super.onResume();
        wakeLock.acquire();
        screen.resume();
        renderView.resume();
    }

    @Override
    public void onPause() {
        super.onPause();
        wakeLock.release();
        renderView.pause();
        screen.pause();

        if (isFinishing())
            screen.dispose();
    }

    @Override
    public Input getInput() {
        return input;
    }

    @Override
    public FileIO getFileIO() {
        return fileIO;
    }

    @Override
    public Graphics getGraphics() {
        return graphics;
    }

    @Override
    public Audio getAudio() {
        return audio;
    }

    @Override
    public void setScreen(Screen screen) {
        if (screen == null)
            throw new IllegalArgumentException("Screen must not be null");

        this.screen.pause();
        this.screen.dispose();
        screen.resume();
        screen.update(0);
        this.screen = screen;
    }

    public Screen getCurrentScreen() {

        return screen;
    }
}

And I do not want to switch to Android Studio. My computer is too poor for this. 🙁


Source: eclipse

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.