我在this教程之後製作了一款安卓遊戲,我想在將其上傳到Google Play商店之前添加admob廣告。我嘗試使用this指南,但我很困惑,因爲我的應用程序不使用layout.xml,只有一個活動。是否可以在不切換活動的情況下在我的應用的某些部分中投放廣告?如果沒有,將我的應用程序轉換爲使用多個活動的應用程序有多難?如有必要,我可以提供任何其他信息。如何通過一項活動將admob廣告添加到我的遊戲中?
這裏是我的活動(我有幾個變化的子類):
package com.kilobolt.framework.implementation;
import android.app.Activity;
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 com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
import com.kilobolt.framework.Audio;
import com.kilobolt.framework.FileIO;
import com.kilobolt.framework.Game;
import com.kilobolt.framework.Graphics;
import com.kilobolt.framework.Input;
import com.kilobolt.framework.Screen;
public abstract class AndroidGame extends Activity implements Game {
AndroidFastRenderView renderView;
Graphics graphics;
Audio audio;
Input input;
FileIO fileIO;
Screen screen;
WakeLock wakeLock;
private AdView mAdView;
@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);
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() {
\t return screen;
}
}
好吧,首先,先生,你有兩個選擇間質和AD瀏覽,所以這是你指的是?並請發佈您希望放置廣告的很大一部分活動,所以人人網可以幫助您 – Elltz
謝謝,我將我的活動添加到了我的文章中! –
sir,勾選[post](https://developers.google.com/mobile-ads-sdk/docs/admob/android/interstitial)..如果您喜歡使用佈局,那麼您將使用'AdView',下面的答案詳細說明了這一點,但你不想使用佈局,那麼你可以使用'interstitial'請檢查** post **它闡述了** Interstitial Add **以及如何將它放入你的應用程序。嘗試一下,如果該職位解決您的要求,請刪除該問題,基於stackoverflow標準它是一個貧窮的問題,因爲缺乏研究.. – Elltz